tidwall / jj

JSON Stream Editor (command line utility)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

pretty should output arrays on multiple lines

opened this issue · comments

proper JQ example:

$ jq '.foxtrot[].golf' hotel.json
"india"
"juliet"
"kilo"

bad JJ example:

$ jj -n -p -i hotel.json 'foxtrot.#.golf'
["india", "juliet", "kilo"]

This is by design. JJ always returns valid json.

@tidwall I am happy with JJ returning valid JSON. I also agree that JQ should
return valid JSON - however I am in bad situation because:

  1. JQ returns arrays on multiple lines, but not as valid JSON
  2. JJ returns valid JSON, but array on single line

The program I end up going with will ideally:

  1. return valid JSON
  2. return arrays on multiple lines, either as the default or with some option

Currently it seems neither program is a complete solution.

This may sound nuts but you could:

jj -i hotel.json 'foxtrot.#.golf' | jq .[]

and ideal solution would be a single program

Update JJ and try this:

jj -l -i hotel.json 'foxtrot.#.golf'

This command:

jj -l -n -i hotel.json 'foxtrot.#.golf'

puts output on multiple lines, but is no longer valid JSON. I am happy with the
result, but I will let you decide if this is acceptable - thanks

puts output on multiple lines, but is no longer valid JSON.

Correct. It can be either multiple lines or valid json. Not both. The -l option outputs multiple lines. Otherwise it's a valid json array.

again I am happy with current result, but it seems JJ should be able to solve
both problems. JQ can solve both this way:

$ jq '[.foxtrot[].golf]' hotel.json
[
  "india",
  "juliet",
  "kilo"
]

Ok. I'm closing this issue now.