Live data from Hacker News

Show HN: Catj – A new way to display JSON files

github.com

61–70 of 127 posts

Re: Show HN: Catj – A new way to display JSON files

#61
post #49
post #20

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…

IIRC in a hashbang isn't posix compatible

A hashbang is not defined by posix, so using it without args isn't "posix compatible".

From https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V...

> If the first line of a file of shell commands starts with the characters "#!", the results are unspecified.

There is no more specification for "#!/usr/bash" than "#!/usr/bin/jq -jf"

The exec page provides even fewer words about how to interpret shebangs if you thought perhaps I was linking to the wrong portion of the posix spec

Re: Show HN: Catj – A new way to display JSON files

#62
post #9

That's nice, I like that. Related, if you want more of a csv-style, see JSONLines. aka "newline-delimited JSON" http://jsonlines.org/

I don't see what jsonlines has over yaml; in fact the jsonlines examples presented there are almost trivially converted to yaml. e.g. the first example is valid yaml if you add a '- ' to each line.

And JSON is (almost) a perfect subset of yaml.

I've been using csv lately. It's reputation is overstated.

What I like is that it's far more compact than yaml or json and trivially pulled into sqlite for ad-hoc queries.

Re: Show HN: Catj – A new way to display JSON files

#64
post #5

Have you seen gron[0]? It's similar: flattens JSON documents to make them easily greppable. But it also can revert (ie, ungron) so you can pipe json to gron, grep -v to remove some data, then ungron to get it back to json. [0] https://github.com/tomnomnom/gron

Love the greppability and reconstructability. This should be the submission.

Re: Show HN: Catj – A new way to display JSON files

#65
post #6
post #5

Have you seen gron[0]? It's similar: flattens JSON documents to make them easily greppable. But it also can revert (ie, ungron) so you can pipe json to gron, grep -v to remove some data, then ungron to get it back to json. [0] https://github.com/tomnomnom/gron

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!

I much prefer jq[1]. Actively developed and written in C.

[1]:https://github.com/stedolan/jq

Re: Show HN: Catj – A new way to display JSON files

#67
post #49

Earlier quoted context omitted.

IIRC in a hashbang isn't posix compatible

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

#69
Okay I made one with javascript ( go to https://underscorejs.org/ and open console )

var json = JSON.parse('{"my": "json"}'); (function printRecursively(ob, _keys = []){ _.map(ob, (val, key) => { var k = _.isNumber(key) ? '[' + key + ']' : '.' + key; var keys = _keys.concat(k); if (_.isObject(val)) printRecursively(val, keys); else console.log(keys.join('') + ' = ' + typeof val + ' ' + val); }); })(json);

EDIT: how do I markup code on HN?

Re: Show HN: Catj – A new way to display JSON files

#70

Okay I made one with javascript ( go to https://underscorejs.org/ and open console ) var json = JSON.parse('{"my": "json"}'); (function printRecursively(ob, _keys = []){ _.map(ob, (val, key) => { var k = _.isNumber(key) ? '[' + key + ']' : '.' + key; var keys = _keys.concat(k); if (_.isObject(val)) printRecursively(val, keys); else console.log(keys.join('') + ' = ' + typeof val + ' ' + val); }); })(json); EDIT: how d…

> how do I markup code

Indent each line with four spaces. Please please keep line length very short (under forty?) as HN's pre tags are absolutely not mobile friendly and can trash the entire page.

Edit: actually it seems to at least scroll within the comment div on overflow now, that's a huge improvement!

Post reply on HN