Skip to content

Instantly share code, notes, and snippets.

@jhmartin
Created August 14, 2019 20:27
Show Gist options
  • Save jhmartin/9e0f6670c1dde344a972e7f9c52309af to your computer and use it in GitHub Desktop.
Save jhmartin/9e0f6670c1dde344a972e7f9c52309af to your computer and use it in GitHub Desktop.
sort jq array
𝑸: How can I sort an inner array of an object? How can I sort all the arrays in a JSON entity? How can I modify a deeply nested array?
A: If the path to the inner entity is known, one can use |= as illustrated here:
{"array": [3,1,2] }
| .array |= sort
To sort all arrays in a JSON entity, no matter where they occur, one option is to use walk/1:
walk( if type == "array" then sort else . end )
https://github.com/stedolan/jq/wiki/FAQ#general-questions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment