Is there a (Unix) shell script to format JSON in human-readable form?
Basically, I want it to transform the following:
{ "foo": "lorem", "bar": "ipsum" }
... into something like this:
{
"foo": "lorem",
"bar": "ipsum"
}
Is there a (Unix) shell script to format JSON in human-readable form?
Basically, I want it to transform the following:
{ "foo": "lorem", "bar": "ipsum" }
... into something like this:
{
"foo": "lorem",
"bar": "ipsum"
}
yajl
is very nice, in my experience. I use itsjson_reformat
command to pretty-print.json
files invim
by putting the following line in my.vimrc
:I usually just do:
And to retrieve select data (in this case, "test"'s value):
If the JSON data is in a file:
If you want to do it all in one go with
curl
on the command line using an authentication token:Vanilla Bash
A simple Bash script (
grep
/awk
) for pretty JSON printing, without third party install:json_pretty.sh
Examples:
1) Read file and pretty print in console
2) Use with the windows GIT Bash from file to file (UTF8 based):
I use jshon to do exactly what you're describing. Just run:
You can also pass arguments to transform the JSON data.
Check out Jazor. It's a simple command line JSON parser written in Ruby.
I wrote a tool that has one of the best "smart whitespace" formatters available. It produces more readable and less verbose output than most of the other options here.
underscore-cli
This is what "smart whitespace" looks like:
I may be a bit biased, but it's an awesome tool for printing and manipulating JSON data from the command-line. It's super-friendly to use and has extensive command-line help/documentation. It's a Swiss Army knife that I use for 1001 different small tasks that would be surprisingly annoying to do any other way.
Latest use-case: Chrome, Dev console, Network tab, export all as HAR file, "cat site.har | underscore select '.url' --outfmt text | grep mydomain"; now I have a chronologically ordered list of all URL fetches made during the loading of my company's site.
Pretty printing is easy:
Same thing:
Same thing, more explicit:
This tool is my current passion project, so if you have any feature requests, there is a good chance I'll address them.