Formatted ("pretty print") JSON output
The -z gives non-formatted output. For "pretty output", there is -Z
zq -z '{"foo":1, "bar":2}'
{foo:1,bar:2}
zq -Z '{"foo":1, "bar":2}'
{
foo: 1,
bar: 2
}
However, there is no JSON equivalent for -Z
zq -j '{"foo":1, "bar":2}'
{"foo":1,"bar":2}
zq -J '{"foo":1, "bar":2}'
flag provided but not defined: -J
For pretty output, i have to opt to secondary tool
zq -j '{"foo":1, "bar":2}' | jq
{
"foo": 1,
"bar": 2
}
Is there a way to get JSON formatted output without reaching to a another tool ?
@hboutou: Thanks for your interest in Zed!
There's not currently a way to get the output you're seeking directly from the Zed CLI tools, but given that -Z exists as you pointed out and how common JSON is, I totally understand why you'd hoped to see it there. I'll take up the topic with the Dev team to see the feasibility of adding this soon and will circle back with an update to this issue.
We discussed this one today as a group. There was consensus that this would indeed be a handy enhancement and probably not too difficult to add. It was pointed out that getting the colored output similar to jq we might mean leveraging JSON libraries other than the standard Go ones, hence maybe looking at projects like https://github.com/itchyny/gojq and https://github.com/TylerBrock/colorjson.
Verified in Zed commit 20a867d.
The new -J option now pretty prints color JSON output.
@hboutou: If you're ok compiling Zed from the tip of main you can take advantage of this right away. Otherwise, it'll be in the next GA Zed release which is expected in the next couple weeks.
Thanks @mattnibs!
Compiled and tested, works like a charm, thank you!