Created
August 14, 2019 20:27
-
-
Save jhmartin/9e0f6670c1dde344a972e7f9c52309af to your computer and use it in GitHub Desktop.
sort jq array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
𝑸: 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