by maleldil · 3y ago · 0 comments
For example, I frequently use jq for queries like this:
jq '.data | map(select(.age <= 25))' input.json
Or this: jq '.data | map(.country) | sort[]' input.json | uniq -c
Is it possible to do something similar with this tool?This is not a slight at jj. Even if it's more limited than jq, it's still of great value if it means it's faster or more ergonomic for a subset of cases. I'm just trying to understand how it fits in my toolbox.
jj 'data.#(age<=25)#' -i input.json
I don't think there is a way to sort an array, though. However, there is an option to have keys sorted. Personally, I don't think there is much annoyance in that. One could just pipe jj output to `sort | uniq -c`.I just discovered that gjson supports custom modifiers [1]. So technically, you could fork jj, and add another file registering `@sort` modifier via `gjson.AddModifier` and have a custom jj version supporting sorting.
[0]: https://github.com/tidwall/gjson/blob/master/SYNTAX.md
[1]: https://github.com/tidwall/gjson/blob/master/SYNTAX.md#modif...