# Sorting arrays of arrays

**URL:** <https://discourse.gohugo.io/t/sorting-arrays-of-arrays/7704>\
**Category:** support\
**Created:** [August 4, 2017, 5:34am UTC](https://discourse.gohugo.io/t/sorting-arrays-of-arrays/7704 "2017-08-04T05:34:32Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jetwash](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jetwash/32/3968_2.png) [@jetwash](https://discourse.gohugo.io/u/jetwash)\
**Post date:** [August 4, 2017, 5:34am UTC](https://discourse.gohugo.io/t/sorting-arrays-of-arrays/7704/1 "2017-08-04T05:34:32Z")

</div>

I have some data which is stored in an array of arrays, and I’m having trouble figuring out how to sort it in Hugo. As a simplified example, consider something like (in YAML):

```auto
data:
- name: A
  items:
  - x: AA
    n: 1
  - x: AB
    n: 5
  - x: AC
    n: 8
- name: B
  items:
  - x: BA
    n: 3
  - x: BB
    n: 2
  - x: BC
    n: 7
- name: C
  items:
  - x: CA
    n: 4
  - x: CB
    n: 6
  - x: CC
    n: 9

```

I’d like to sort by `n`, so that C is output first (since the highest `n` in C is CC, which is 9) then A (since AC is 8), then B (since BC is 7). Is there a way to do this in Hugo?

Simply sorting the input file isn’t a very good option, since it would result in a lot of churn in the files, and make them more difficult to maintain… The fallback is probably adding some sort of preprocessor, which I’m trying quite hard to avoid.
