A good opportunity to introduce `gron` to those unfamiliar!
▶ 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 = "[email protected]";
json[0].commit.author.name = "Tom Hudson";
https://github.com/tomnomnom/gronThank you - appreciated.
I haven't done much work with json but have had reasons recently to do so - and I immediately saw how difficult it was to pipeline to grep ...
But what I still don't understand is that some json outputs I see have multiple values with the exact same name (!) and that still seems "un-grep-able" to me ...
What am I missing ?
> But what I still don't understand is that some json
> outputs I see have multiple values with the exact same name
This is neither explicitly allowed nor explicitly forbidden by the JSON spec. It is implementation dependent upon how to handle - does one value override the other? Should they be treated as an array?In practice, this situation is usually carefully avoided by services that produce JSON. If you are interfacing with a service that does produce duplicate values, I'd be interested in seeing it for curiosity's sake. If you are writing a service and this is the output, then I implore you to reconsider!
It seems both gron and jq only use the value that has been defined last:
~ echo '{"a":1,"a":2}' | gron
json = {};
json.a = 2;
~ echo '{"a":1,"a":2}' | jq
{
"a": 2
}It doesn't handle malformed HTML that well but can be coaxed into working about 90% of the time, with the help of the other included package hxclean or something like html-tidy.
This is the kind of obvious tool that once it exists, you can’t really grok the fact it did not earlier, and that it took until now to exist.