Sorting arrays of arrays

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):

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.