I prefer python -m json.tool
which seems to be available per default on most *nix operating systems per default.
$ echo '{"foo":1, "bar":2}' | python -m json.tool
{
"bar": 2,
"foo": 1
}
Note: Depending on your version of python, all keys might get sorted alphabetically, which can or can not be a good thing. With python 2 it was the default to sort the keys, while in python 3.5+ they are no longer sorted automatically, but you have the option to sort by key explicitly:
$ echo '{"foo":1, "bar":2}' | python3 -m json.tool --sort-keys
{
"bar": 2,
"foo": 1
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…