command-line - bash script to read values from json file - How can I pretty-print JSON in a shell script?

unix json / json / unix / format / pretty-print

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

16 revs, 12 users 29%AnC



Answer #1

For example:

cat xxx | jq .