Hacker News new | past | comments | ask | show | jobs | submit login

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



If you have `jq` installed then you can just pipe any JSON to `jq` and it will beautify and colorize it automatically.

  pbpaste | jq


+1 for JQ, I use it in just about any place I can


One 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...


Which VSCode plugin are you using for this? I’m not sure what to search to find it but it sounds handy :)


My 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...

But I've also written about how to do it with various stacks for various things at https://www.jvt.me/tags/pretty-print/


Or

    cat foo.json | python3 -m json.tool
Prettifying is also built in to python3 on any system.


Or

    jq  . foo.json


jq 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/


useless use of cat:

python3 -m json.tool foo.json


Usually 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"




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: