Last Updated: February 25, 2016
· jacaetevha

More JSON formatting

I see a lot of folks posting about JSON formatting using Python's JSON formatter (eg. http://coderwall.com/p/faceag). There is also the yajl tools library which is very fast. It offers you the jsonreformat and jsonverify commands.

On Mac:

brew install yajl

On some Linux distros:

apt-get install yajl-tools

You can pipe JSON output to it like this:

<some command returning JSON> | json_reformat

You can use it in your Vim buffers:

:%! json_reformat

... or:

:%! json_verify

Finally, here's what each command can accomplish:

json_reformat: reformat json from stdin

usage:  json_reformat [options]
    -m minimize json rather than beautify (default)
    -u allow invalid UTF8 inside strings during parsing
    -e escape any forward slashes (for embedding in HTML)

json_verify: validate json from stdin

usage: json_verify [options]
    -q quiet mode
    -c allow comments
    -u allow invalid utf8 inside strings