Created
April 9, 2012 15:55
-
-
Save fundon/2344394 to your computer and use it in GitHub Desktop.
use JSON.stringify to pretty-print JSON.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function formatjson() { | |
local json="" | |
if [ -p /dev/stdin ]; then | |
# piping, e.g. `echo '{"foo":42}' | formatjson` | |
while read -r line; do | |
json="$json$line" | |
done | |
else | |
# e.g. `formatjson '{"foo":42}'` | |
json="$*" | |
fi | |
node -e "console.log(JSON.stringify(eval($json), null, 2));" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment