Live data from Hacker News

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

github.com

11–20 of 127 posts

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

#13
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

What does grep + gron give you over jq?

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

#14
The output format like a slightly better INI (in that it would support deeper hierarchies), although arrays would be a pain to write an index at a time like that.

And for purely aesthetic, nitpicky reasons I think the leading period in each line is redundant.

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

#15
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

What does grep + gron give you over jq?

as far as i can tell, jq doesn't do flattening .

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

#16
post #15

Earlier quoted context omitted.

What does grep + gron give you over jq?

as far as i can tell, jq doesn't do flattening .

Maybe GP meant that jq can do selection as well, i.e. that grepping is redundant after jq. But jq is much more complicated to learn and grep works on all inputs (not just json), so it makes a lot more sense to learn and use grep properly.

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

#17
post #14

The output format like a slightly better INI (in that it would support deeper hierarchies), although arrays would be a pain to write an index at a time like that. And for purely aesthetic, nitpicky reasons I think the leading period in each line is redundant.

I don't think that leading period is redundant. It indicates that the top-level value is an object, as opposed to an array or some basic value.

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

#18
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

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.

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

#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 shebang:

  #!/usr/bin/jq -jf
Post reply on HN