
Curl will now output JSON - logicalstack
https://daniel.haxx.se/blog/2020/03/17/curl-write-out-json/
======
dTal
I think if all command line tools outputted JSON, it would go a long way
towards fixing the "ad-hoc parser problem" in scripts, and bring unixy shells
around to a more PowerShell-like object-passing style. Passing plain text
around is a great idea, but It's silly to restrict yourself to a single
structural unit within that text (the "line"). We have better tech now.

~~~
nyberg
It's nice but I don't think json is such a great format for it. The overhead
of parsing it is incredibly annoying along with being unable to pack binary
data which is what unix tools can deal with to some extent

~~~
rantwasp
i have 2 letters for you: jq

any tool that outputs json + jq => instant scriptability win.

~~~
technofiend
Particularly if you prepend queries with try. jq likes to throw errors when
unexpected things happen in your search or your data, and it may return
"null". Using try instead returns an empty string.

When walking JSON structures to validate data I code each validation
separately instead of burying them in blocks of if-then-else logic. I think
this makes it easier to maintain and more obvious when dealing with data that
for example may be in a list or an array of lists.

But yeah if you write golang scripts and want to shuffle data in and out of
bash, jq is your #1 power tool.

------
enriquto
No need to panic! You can still pipe it to gron [0] and recover useable
output.

[0] [https://github.com/TomNomNom/gron](https://github.com/TomNomNom/gron)

------
quintonish
Note that this is not titled, "Curl will now format JSON". This will "Make
curl display information on stdout after a completed transfer"[1].

[1]
[https://curl.haxx.se/docs/manpage.html#-w](https://curl.haxx.se/docs/manpage.html#-w)

------
theMiddleBlue
I'm testing it, maybe I'm doing it wrong but I don't understand well if it's
possible to show only the json output (and not both json and response body).
I'm doing it with a trick:

curl -I -XGET -w '%{json}' [https://www.google.com](https://www.google.com) |
tail -1 | jq

~~~
otterlicious

        -o /dev/null

------
rossmohax
It is a step in the right direction, but still far from all the goodnes of
PowerShell's Invoke-WebRequest . Not sure curl can do anything about it
though.

------
MuffinFlavored
Do you still need to pass it to `jq` for it to be pretty printed or no, I
couldn't tell from reading the article?

~~~
kuesji
yes, you still need 'jq' for pretty print.

------
pyuser583
That’s nice.

------
monkey26
To bad this requires nightly.

------
omani
beautiful. thank you for this.

