Hacker News new | ask | show | jobs
by ishandotpage 932 days ago
Have you tried `gron`?

It converts your nested json into a line by line format which plays better with tools like `grep`

From the project's README:

▶ gron "https://api.github.com/repos/tomnomnom/gron/commits?per_page..." | 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";

https://github.com/tomnomnom/gron

It was suggested to me in HN comments on an article I wrote about `jq`, and I have found myself using it a lot in my day to day workflow

4 comments

This is awesome, thanks! Not OP, but this will help me to write specifications for modifying existing JSON structures immensely. It's kind of a pain parsing JSON by (old man) eye to figure out which properties are arrays, and follow property names down a chain. This will definitely help eliminate mistakes!
Also try jless[0], it's amazingly convenient and it shows you a JSON path at the bottom of the screen as you navigate.

[0] https://jless.io/

Thank you so much. This seems like a saner approach for some simpler use cases.

It flattens the structure. And makes for easy diffing.

There's also this awesome tool to make JSON interactively navigable in the terminal:

https://fx.wtf

https://jless.io/ is similar, and will give you jq selectors so the two combine very well. (fx might have that feature too, I dunno)
Ah thanks, jless is actually the one I was originally thinking of and trying to find! :D
You can also mimic gron, including support for yaml with

yq -o=props my-file.yaml

Doesn't work in my terminal. When you recommend yq behavior, please specify which yq you're using. There are at least two incompatible implementations.
This looks some much better as an ad-hoc tool. Would be cool if it supported more formats - plist, yaml, xml (hoow to do body, or conflicting attr/elements)