4 ms·
OS X includes the json_pp command, so I often just do this to format JSON in my clipboard: pbpaste | json_pp | pbcopy For just viewing, I like Node's conso
by tlrobinson 7y ago
OS X includes the json_pp command, so I often just do this to format JSON in my clipboard:
pbpaste | json_pp | pbcopy
For just viewing, I like Node's console.dir() formatting better since it's more compact and colored (but it's unquoted JS objects, not JSON), so I aliased this command in my shell:
json='node -e '\''console.dir(JSON.parse(fs.readFileSync("/dev/stdin", "utf-8")), { depth: null })'\'
Then I can do
pbpaste | json
- tonyhb 7y agoOr cat foo.json | python3 -m json.tool Prettifying is also built in to python3 on any system.
- pstuart 7y agoOr jq . foo.json
- vesinisa 7y agojq is freaking awesome! It can do amazing stuff, it's like awk for JSON on steroids. Highly recommend reading the documentation: https://stedolan.github.io/jq/manual/ https://stedolan.github.io/jq/manual/
- fs111 7y agouseless use of cat: python3 -m json.tool foo.json
- dheera 7y agoUsually though what happens is this: :) cat foo.json [oh crap] :) cat foo.json | python -m foo.tool For the 2nd command I'd hit "[up] | pyth[tab] -m json.tool"
- eridius 7y agoIf you have `jq` installed then you can just pipe any JSON to `jq` and it will beautify and colorize it automatically. pbpaste | jq
- LeonM 7y ago+1 for JQ, I use it in just about any place I can
- gregopet 7y agoOne of my absolute musts in a text editor is a feature that prompts for a command, pipes the selected text into it and replaces it with the command's output (for Visual Studio Code it comes as a plugin). So "Ctrl+A, Ctrl+\, 'json_pp', Enter" and voila, formatted JSON in my editor (Ctrl+\ is what the command is bound to). Also works great with grep, sort, awk...
- mcintyre1994 7y agoWhich VSCode plugin are you using for this? I’m not sure what to search to find it but it sounds handy :)
- jamietanna 7y agoMy favourite hack is that jf you have a python installation (common on most Linux/Mac environments), you likely can use `python -mjson.tool` https://www.jvt.me/posts/2017/06/05/pretty-printing-json-cli/ https://www.jvt.me/posts/2017/06/05/pretty-printing-json-cli... But I've also written about how to do it with various stacks for various things at https://www.jvt.me/tags/pretty-print/ https://www.jvt.me/tags/pretty-print/