Earlier quoted context omitted.
Actively developed and written in Go. The project linked to is from 2014 with last update in 2015.and it is on NPM... What is left to say? Thank you!
What's wrong with it not being updated in 5 years? It's a simple script. It's probably stable and doesn't need to be "actively developed".
Show HN: Catj – A new way to display JSON files
91–100 of 127 posts
Re: Show HN: Catj – A new way to display JSON files
#92This may look cute but it is horrific when dealing with large configs and you have to reconstruct all the structure in your head.
Also, when you have a format that nests using brackets, braces and parenthesis, you can get help from the editor. This format does not give you that.
I'm not a huge fan of JSON (and the above mentioned format was invented because none of us were fans of XML at the time), but it turns out that both XML and JSON are actually easier to work with in practice than this format. Not least because there is ample tooling for JSON (and XML).
The lesson I learnt: I may hate XML (or in this case JSON), but finding an alternative that is better is not easy.
Re: Show HN: Catj – A new way to display JSON files
#93Re: Show HN: Catj – A new way to display JSON files
#94Earlier quoted context omitted.
Your opinion is bad.
json will be mocked in a few years by the same people that today mock xml. In the end, unix always survives.
XML is native to nothing. It's annoying to use everywhere.
UNIX tools just don't compare. Sure, they stick around, because sometimes they're the easiest tool for some job, until they aren't and you regret starting out with them.
In a few years, Javascript and Javascript-compatible languages are likely to be bigger than ever before. A whole generation of developers has been trained mainly on them. Billions of dollars have been invested into the ecosystem. Whether we like it or not, that's the reality. For that reason alone, JSON will stick around.
Re: Show HN: Catj – A new way to display JSON files
#95Re: Show HN: Catj – A new way to display JSON files
#96I 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…
That's awesome work. The only problem is that it does not properly handle keys which are not valid JS identifiers (like 1foo, @foo, foo-bar, etc.).
jq -r '
tostream
| select(length > 1)
| (.[0] | map("[" + @json + "]") | join(""))
+ " = " + (.[1] | @json)
'
And this other option with the blacklist patterns: jq -r '
tostream
| select(length > 1)
| (
.[0] | map(
if type == "number" or (tostring | test("[@-]|^[0-9]|^else$"))
then "[" + @json + "]"
else "." + .
end
) | join("")
) + " = " + (.[1] | @json)
'
(The blacklist here is non-exhaustive, but an example.)Re: Show HN: Catj – A new way to display JSON files
#97That said, if you're stuck dealing with bad JSON like this with low signal to noise this is a decent way to redisplay it.
Re: Show HN: Catj – A new way to display JSON files
#98deno install catj https://deno.land/std/examples/catjson.ts --allow-read
Re: Show HN: Catj – A new way to display JSON files
#99Earlier quoted context omitted.
Appending | to each line and a last line . is a jq program that reproduces the original json. jq -r ' ( tostream | select(length > 1) | ( .[0] | map( if type == "number" then "[" + tostring + "]" else "." + . end ) | join("") ) + " = " + (.[1] | @json) + " |" ), "." '
That's insane. Here I was thinking about how much more challenging it would be to parse and reconstruct the object from jq, and you got the idea to take advantage of the syntax similarity to parse it as jq code itself. Nice. And so, that means the inverse of the jq code I posted would simply be: ( jq "$(sed 's/$/ |/;$a.')" As in: catj example.json \ | ( jq "$(sed 's/$/ |/;$a.')" original.json
BTW the input json can be null, so -n works (also using process substitution):
jq -nf Re: Show HN: Catj – A new way to display JSON files
#100I 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…
jq: error: syntax error, unexpected INVALID_CHARACTER, expecting $end (Unix shell quoting issues?) at , line 3: jq -j ' jq: 1 compile error This, uh, doesn't work for me on jq-1.5.1.