I 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…
Show HN: Catj – A new way to display JSON files
81–90 of 127 posts
Re: Show HN: Catj – A new way to display JSON files
#82This is a nice CLI based alternative
Re: Show HN: Catj – A new way to display JSON files
#83 function cason(x){
switch(x[0]){
case "movie": switch(x[1]) {
case "name" : return "Interstellar";
case "year" : return 2014;
case "is_released": return true;
case "director" : return "Christopher Nolan";
case "cast": switch(x[2]){
case 0: return "Matthew McConaughey";
case 1: return "Anne Hathaway";
case 2: return "Jessica Chastain";
case 3: return "Bill Irwin";
case 4: return "Ellen Burstyn";
case 5: return "Michael Caine";
}
}
}
}Re: Show HN: Catj – A new way to display JSON files
#84Earlier quoted context omitted.
Args in a hashbang? Maybe not, but I'm pretty sure every system supports a single arg. And very few (none?) support more.
macOS appears to support multiple args just fine. Which is why it annoys me that Shellcheck bitches about using more than one arg even though I'm writing a script for macOS specifically.
Re: Show HN: Catj – A new way to display JSON files
#85https://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
> combine with bash alias ... 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.
Re: Show HN: Catj – A new way to display JSON files
#86The text streams that are processed line-by-line by dozens or hundreds of line-based tools are immensely powerful and universal. It's all Unix heritage and often overlooked by fancy modern designs that more often follow a fashion rather than root themselves in substance.
Surely text streams have their share of limitations like everything else but in practise you can retrofit nearly anything into line-based text streams and get an immediate productivity multiplier by being able to apply a whole array of established tools to process that data. Proof of that power is that it has been worthwhile to write converters to and from text and other formats. Not only you can find translators to turn various hierarchical or object-oriented formats into text but you can even convert a PNG into text and back (with SNG).
Text streams are like roads with lanes. They're ages old, they're pretty good at separating and guiding traffic, and they're somehow suboptimal in several senses yet rarely can anyone point out a single, clear practical improvement on laned roads, not to mention a system for containing traffic flows that is superior to them.
Re: Show HN: Catj – A new way to display JSON files
#87https://github.com/zacharyvoase/jsonpipe
It includes 'jsonunpipe'.
So you could grep part of the JSON and still get a JSON back.
``` echo '{"a": 1, "b": 2}' |grep b| jsonpipe | jsonunpipe
#{""b": 2} ```
Re: Show HN: Catj – A new way to display JSON files
#88I 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.Re: Show HN: Catj – A new way to display JSON files
#89(I haven’t run it, but a skim of the code suggests that this tool will turn `{"foo.bar": "baz", "foo": {"bar": "baz"}}` into `["foo.bar"] = "baz"` and `.foo.bar = "baz"`, resolving the separator ambiguity in a pretty JavaScripty way.)
Re: Show HN: Catj – A new way to display JSON files
#90Here's a Python implementation of gron https://github.com/venthur/python-gron