News for hackers. Stuff that matters.
Re:Jj: JSON Stream Editor by maleldil on Friday May 26, 2023 @04:34AM (#36081575)
Am I correct in understanding that this can only manipulate (get or set values) from a JSON path? That is, is it not a replacement for jq?

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.

Re:Jj: JSON Stream Editor by zimpenfish on Saturday May 27, 2023 @02:07AM (#36092451)
Annoyingly, I think `jq` might still be the only tool capable of these kinds of things. The rest seem to be "query simple paths and print the result" (which is handy, of course - I often use `gron` to get an idea of the keys I'm after because the linear format is easier to handle than JSON.)
Re:Jj: JSON Stream Editor by TymekDev on Monday May 29, 2023 @05:52AM (#36112370)
It looks like the README in jj repository does not do justice when it comes to available syntax for queries. jj uses gjson (by the same author) and its syntax [0]. From what I saw the first one can be handled with:

    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...