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"
}
1 email / week to learn how to (ab)use technology for fun & profit: Programming, Hacking & Entrepreneurship.
I hate spam even more than you do. I'll never share your email, and you can unsubscribe at any time.

Tags: programming, webdev, bash

Want to learn Rust, Cryptography and Security? Get my book Black Hat Rust!