top | item 40100242

(no title)

bsdetector | 1 year ago

JSON is literally key=value, just nested. Which you can do with shell variables.

The question was "What's not to like [about JSON output from cmdline tools]?" and the answer is that it's cumbersome to read in a shell and all but requires another pipeline stage.

I didn't even recommend shell variable output and made it clear this isn't today a reasonable solution so I'm not sure where this hostility in the replies comes from, but I assume from recognition that it's a more practical solution to reading data within a shell but not wanting that to be so.

discuss

order

starttoaster|1 year ago

> JSON is literally key=value, just nested.

The nature of being nested, and also containing structures like lists, maps, etc. All of which makes it more complicated than key=value.

> The question was "What's not to like [about JSON output from cmdline tools]?" and the answer is that it's cumbersome to read in a shell and all but requires another pipeline stage.

It depends on the intended use for your shell program. If you intend the CLI tool to be used in CI pipelines (eg. your CLI tool's output is being read by an automated process on a computer) and the data it outputs is more complicated than a simple key=value, JSON is great for that. Your CI program can pipe to jq. You as a human can pipe to jq, though I agree it's somewhat less desirable. Though just piping to jq without any arguments pretty prints it for you which also makes it fairly readable for humans.

> so I'm not sure where this hostility in the replies comes from

You're reading into hostility where there isn't any.

bsdetector|1 year ago

> The nature of being nested, and also containing structures like lists, maps, etc. All of which makes it more complicated than key=value.

These are javascript objects, which are key-value. A list array is just keyed by a number instead of a string. They're functionally exactly the same as name=value except JSON is parsed depth-first whereas shell variables are breadth-first parsing (which is way better from shells).

Do you have an example of a CLI tool - intended for human use - that has output so complicated it can't be easily mapped to name=value? I don't think there is one, and it's certainly not common.

> You're reading into hostility where there isn't any.

I think "it seems you're determined not to use jq" is pretty hostile since I made no intimation of that at all.