3 ms·
As someone who has been using jq for years, my first instinct was why not jq? and while it answers it in the README as well, it is not very clear until you comp
by omeid2 3y ago
As someone who has been using jq for years, my first instinct was why not jq? and while it answers it in the README as well, it is not very clear until you compare the output to jq.
$ gron "https://api.github.com/repos/tomnomnom/gron/commits?per_page=1" | fgrep "commit.author"
json[0].commit.author = {};
json[0].commit.author.date = "2016-07-02T10:51:21Z";
json[0].commit.author.email = "mail@tomnomnom.com";
json[0].commit.author.name = "Tom Hudson";
And with jq:
$ curl "https://api.github.com/repos/tomnomnom/gron/commits?per_page=1" | jq ".[].commit.author"
{
"name": "Tom Hudson",
"email": "mail@tomnomnom.com",
"date": "2022-04-13T14:23:37Z"
}
The jq version isn't greppable, as you can't do `| grep '.author.email'` for example.
- inferiorhuman 3y agoTheoretically jq can be coerced into printing similar output. Realistically though if you've already written that jq query and you wanted the email field you'd just append .email. https://unix.stackexchange.com/questions/561460/how-to-print-path-and-key-values-of-json-file#answer-760188 https://unix.stackexchange.com/questions/561460/how-to-print...
- hyperthesis 3y agoFlattening facilitates arbitrary ad hoc transformation.
- ivanhoe 3y ago> The jq version isn't greppable, as you can't do `| grep '.author.email'` for example. Truth to be told with jq you don't need to grap it, you can grab just emails directly. I find gron a lot more useful for grep -v, that is for filtering out the parts that you don't need. Super easy to clean up data.
- zimpenfish 3y ago`gron` is super useful when you don't directly know the structure of some JSON - gives you a nice simple path to locate things you can then construct a `jq` query to deal with (since e.g. dealing with multiple items in the same list can be a faff with `gron`.)
- swah 3y agoAnother option: jless. You can then copy the path and use in jq with "yq".
- __MatrixMan__ 3y agoI think of gron and jq as siblings: gron + grep for discovery, then you use gron's output (for the desired line) as jq's input, which shows you what you were after. With jq alone, you have to already understand the structure, which isn't always a given if you're combing through k8s manifests for instance.