How to format and prettify curl JSON output
So you have this curl
shell/bash command that fetches some JSON, but unfortunately the JSON is sent without any space or newline which make it hard to read.
Here are a few ways to display curl output in readable JSON format.
Using python
Whether it be macOS or Linux, python
is installed by default almost anywhere.
$ echo '{"hello":"world"}' | python3 -m json.tool
{
"hello": "world"
}
Using NodeJS
$ echo '{"hello":"world"}' | node -e "console.log(JSON.stringify(JSON.parse(require('fs').readFileSync(0)), 0, 1))"
{
"hello": "world"
}
Using jq
jq is a lightweight and flexible command-line JSON processor.
$ echo '{"hello":"world"}' | jq '.'
{
"hello": "world"
}