Skip to content

Instantly share code, notes, and snippets.

@horttanainen
Last active March 7, 2019 13:03
Show Gist options
  • Save horttanainen/110b248408d39a57d5d371919dc9faa0 to your computer and use it in GitHub Desktop.
Save horttanainen/110b248408d39a57d5d371919dc9faa0 to your computer and use it in GitHub Desktop.
Pretty print JSON without jq using node
#!/usr/bin/env bash
node -e 'var fs = require("fs"); process.stdin.resume(); process.stdin.setEncoding("utf8"); var data = ""; process.stdin.on("data", function(buf) { data += buf; }); process.stdin.on("end", function() { console.log(JSON.stringify(JSON.parse(data), null, 2)); });'
@horttanainen
Copy link
Author

horttanainen commented Mar 7, 2019

Add the snippet in your .bashrc

alias pjson='sh ~/.scripts/pretty-print-json.sh'

Try it out:

curl https://jsonplaceholder.typicode.com/todos/1 | tr -d '\n' | pjson

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment