Earlier quoted context omitted.
What does grep + gron give you over jq?
as far as i can tell, jq doesn't do flattening .
Show HN: Catj – A new way to display JSON files
31–40 of 127 posts
Re: Show HN: Catj – A new way to display JSON files
#32I was curious if this could be doable with jq, and apparently it is: jq -j ' [ [ paths(scalars) | map( if type == "number" then "[" + tostring + "]" else "." + . end ) | join("") ], [ .. | select(scalars) | @json ] ] | transpose | map(join(" = ") + "\n") | join("") ' EDIT: Got the string quoting and escaping. EDIT 2: For those who want to save this script, you can put just the jq code in an executable file with the s…
Re: Show HN: Catj – A new way to display JSON files
#33Re: Show HN: Catj – A new way to display JSON files
#34For exploring large files I released a program called "JSONSmash" that runs a shell which lets you browse the data as if it was a filesystem. https://blog.tedivm.com/open-source/2017/05/introducing-json...
I've used JSONExplorer for this purpose, but it is web based and doesn't handle files this large.
Extending the filesystem metaphor to JSON data and re-using the same commands strikes me as a great idea.
Did another project inspire you, or did you come up with the concept yourself?
Have you done a Show HN yet?
Re: Show HN: Catj – A new way to display JSON files
#35It looks almost executable! If it were, that might be handy now and then.
Re: Show HN: Catj – A new way to display JSON files
#36I was curious if this could be doable with jq, and apparently it is: jq -j ' [ [ paths(scalars) | map( if type == "number" then "[" + tostring + "]" else "." + . end ) | join("") ], [ .. | select(scalars) | @json ] ] | transpose | map(join(" = ") + "\n") | join("") ' EDIT: Got the string quoting and escaping. EDIT 2: For those who want to save this script, you can put just the jq code in an executable file with the s…
Would probably be shorter if you used `tostream`
jq -r '
tostream
| select(length > 1)
| (
.[0] | map(
if type == "number"
then "[" + tostring + "]"
else "." + .
end
) | join("")
) + " = " + (.[1] | @json)
'
EDIT: For those who want to save this script, you can put just the jq code in an executable file with the shebang: #!/usr/bin/jq -rfRe: Show HN: Catj – A new way to display JSON files
#37jq can also do the same thing, with more flexibility. And it is possible to combine with bash alias to make it indistinguishable from catj
Re: Show HN: Catj – A new way to display JSON files
#38this is not merely a display, it is really a sanitation of the brain-damaged json syntax.
What method would you use to serialize data structures into a format that is both easily read and written by both a computer and a human?
Re: Show HN: Catj – A new way to display JSON files
#39Earlier quoted context omitted.
What does grep + gron give you over jq?
jq seems very powerful. I don't deal with json all that often and my most common use case (by far) is `jq '.' -C` and it took a few tries for me to remember that syntax. The idea of flattening, grepping, then reverting sounds very appealing and sounds like a better fit for me.
I don't think you really need neither `.` nor `-C`. Just `jq` seems to do the same colored output of the input by default.
Re: Show HN: Catj – A new way to display JSON files
#40https://github.com/stedolan/jq/issues/243 jq can also do the same thing, with more flexibility. And it is possible to combine with bash alias to make it indistinguishable from catj
... or you know, you could put the jq script in an executable file and add a shebang like
#!/usr/bin/jq -jf
or #!/usr/bin/jq -rf
In my opinion, aliases should mostly be used to add default options only. Not really to insert whole scripts into them.