4 ms·
To better appreciate the structure of the document the author is dealing with (and to cast a bit of light on which words are variables in the document and which
by tejtm 5y ago
To better appreciate the structure of the document the author is dealing with (and to cast a bit of light on which words are variables in the document and which are `jq` syntax.
I offer a shameless plug to a one liner
well,
I would but the result is "too long for a HN comment"
so here a bunch is sniped out of the middle
(unedited the result would currently be 140 lines)
curl -s https://hn.algolia.com/api/v1/items/27941108 | ~/bin/json2jqpath.jq
.
.author
.children
.children|.[]
.children|.[]|.author
.children|.[]|.children
.children|.[]|.children|.[]
.children|.[]|.children|.[]|.author
.children|.[]|.children|.[]|.children
.children|.[]|.children|.[]|.children|.[]
.children|.[]|.children|.[]|.children|.[]|.author
.children|.[]|.children|.[]|.children|.[]|.children
.children|.[]|.children|.[]|.children|.[]|.children|.[]
<snip>
...
</snip>
.children|.[]|.children|.[]|.created_at
.children|.[]|.children|.[]|.created_at_i
.children|.[]|.children|.[]|.id
.children|.[]|.children|.[]|.options
.children|.[]|.children|.[]|.parent_id
.children|.[]|.children|.[]|.points
.children|.[]|.children|.[]|.story_id
.children|.[]|.children|.[]|.text
.children|.[]|.children|.[]|.title
.children|.[]|.children|.[]|.type
.children|.[]|.children|.[]|.url
.children|.[]|.created_at
.children|.[]|.created_at_i
.children|.[]|.id
.children|.[]|.options
.children|.[]|.parent_id
.children|.[]|.points
.children|.[]|.story_id
.children|.[]|.text
.children|.[]|.title
.children|.[]|.type
.children|.[]|.url
.created_at
.created_at_i
.id
.options
.parent_id
.points
.story_id
.text
.title
.type
.url
[0] https://github.com/TomConlin/json_to_paths https://github.com/TomConlin/json_to_paths
- woodruffw 5y agoThanks for linking this! I've wanted exactly this script, many times.
- naniwaduni 5y agoLooks a bit like `jq -rc '[path(..)|map(strings//"[]")]|unique[]|"."+join("|.")'`, but might I suggest `jq -rc '[paths|map(("."+strings)//"[]")|join("")]|unique[]'`?
- tejtm 5y agoThere is no need to guess, you can just look in the repo. I like the explicit separators when I'm reading them instead of writing them. Helps the individual steps stand out for me. Is there a reason other than a more compact line?