jp

jp is a command line tool that reformats JSON to make it easier to read:

$ cat names.json
{"names":["Paul","Amy"]}
$ jp names.json
{
  "names": [
    "Paul",
    "Amy"
  ]
}

It only adds and removes whitespace, which means that your data won’t get silently altered. For example, "\u2603" won’t get converted to "☃", and 1.1e1 won’t turn into 11. The ordering remains the same, and invalid JSON can be reformatted (within reason). This stuff shouldn’t matter, but people make mistakes even with a well defined format like JSON, and accurate tools are important when you’re trying to work out what’s gone wrong.

It’s also insanely fast because it reformats the data without decoding then reencoding it.

Installing

Download a zip file, then copy the jp file inside to somewhere in your path:

The source code is available if you’d prefer to compile it yourself.

Using

To prettify a JSON file:

jp data.json

To prettify from stdin, use - as the filename:

curl -sL http://phmmnd.me/names.json | jp -

To compact a JSON file:

jp --compact data.json

Development

The source and bug list for jp are on GitHub.