[0] https://github.com/tomnomnom/gron
"Make JSON greppable!"
"gron transforms JSON into discrete assignments to make it easier to grep for what you want and see the absolute 'path' to it."
31–40 of 65 posts
[0] https://github.com/tomnomnom/gron
"Make JSON greppable!"
"gron transforms JSON into discrete assignments to make it easier to grep for what you want and see the absolute 'path' to it."
gron [0] is another interesting JSON processor that follows UNIX philosophy: [0] https://github.com/tomnomnom/gron "Make JSON greppable!" "gron transforms JSON into discrete assignments to make it easier to grep for what you want and see the absolute 'path' to it."
JQ syntax feels too unusual, doesn't resemble known code, gives me the feeling of looking into cryptic Perl or regex, could never remember the simplest things. For example how would you take key k1 from a list of dicts [{k1: v1, k2: v2}, {k1: v3}]?
Had the same experience. That's why I've written jql[0], which puts a uniform lispy spin on CLI JSON processing. I now use it almost exclusively instead of jq. Check it out if you're looking for alternatives. And by the way, you can achieve live preview with any of these CLI tools by using fzf. This is the snippet for jql for example: `echo '' | fzf --print-query --preview-window wrap --preview 'cat test.json | jql {…
Earlier quoted context omitted.
Had the same experience. That's why I've written jql[0], which puts a uniform lispy spin on CLI JSON processing. I now use it almost exclusively instead of jq. Check it out if you're looking for alternatives. And by the way, you can achieve live preview with any of these CLI tools by using fzf. This is the snippet for jql for example: `echo '' | fzf --print-query --preview-window wrap --preview 'cat test.json | jql {…
`jql` looks interesting - is there an easy way to do the equivalent of `jq`'s `to_entries[]`? (e.g. turns `{"x":"y"}{"a":"b"}` into `{"key":"x","value":"y"}{"key":"a","value":"b"}` which I've needed a lot recently for dealing with output with unknown keys.)
For the special case you wrote as an example, where each object is just a single key-value, it's possible:
(object
"key" (pipe (keys) (0))
"value" (pipe ((keys)) (0)))Earlier quoted context omitted.
> I have found great mileage using gron `gron` is great but doesn't seem to handle some (extreme-ish) situations that `jq` can, e.g. the json output from the fastnbt-tools. You either get a `token too long` error using `gron -s` because the input is too long (it's 90MB, that's fair) or you get only one set of outputs per key (iyswim) because they get overlapped in memory.
> or you get only one set of outputs per key (iyswim) because they get overlapped in memory That sounds like a major bug. So it will silently skip data that you wanted?
It's definitely an oddness when you have multiple objects at the same level that aren't in an array but I guess the explanation there is "they should all be on their own individual lines as streaming json" which `gron` does handle correctly.
(echo '{"a":"23"}'; echo '{"a":"25"}') | gron -s
json = [];
json[0] = {};
json[0].a = "23";
json[1] = {};
json[1].a = "25";
> So it will silently skip data that you wanted?Yeah.
echo '{"a":"23"}{"a":"25"}' | gron
json = {};
json.a = "23";
The `-s` option doesn't help. echo '{"a":"23"}{"a":"25"}' | gron -s
json = [];
json[0] = {};
json[0].a = "23";Earlier quoted context omitted.
`jql` looks interesting - is there an easy way to do the equivalent of `jq`'s `to_entries[]`? (e.g. turns `{"x":"y"}{"a":"b"}` into `{"key":"x","value":"y"}{"key":"a","value":"b"}` which I've needed a lot recently for dealing with output with unknown keys.)
For the general case of multiple keys and values - no. It sounds reasonable, though, so I'll think about whether to add an entries function or a map function that would allow doing this in a simple way. For the special case you wrote as an example, where each object is just a single key-value, it's possible: (object "key" (pipe (keys) (0)) "value" (pipe ((keys)) (0)))
That would be super, ta. `to_entries[]` is pretty much the major reason I've not managed to move off `jq` to anything else yet because it's just incredibly powerful in this situation.
Earlier quoted context omitted.
For the general case of multiple keys and values - no. It sounds reasonable, though, so I'll think about whether to add an entries function or a map function that would allow doing this in a simple way. For the special case you wrote as an example, where each object is just a single key-value, it's possible: (object "key" (pipe (keys) (0)) "value" (pipe ((keys)) (0)))
> I'll think about whether to add an entries function or a map function that would allow doing this in a simple way. That would be super, ta. `to_entries[]` is pretty much the major reason I've not managed to move off `jq` to anything else yet because it's just incredibly powerful in this situation.
The relevant jql snippet to solve this in the general case now is:
(pipe
(zip
(keys)
((keys)))
((keys)
(object
"key" (0)
"value" (1))))
It's not as terse as the jq equivalent - I'll probably add a way to create user-defined functions, so you can alias stuff like this to shorter forms - but that one will require more thought.