Python documentation here
Example usage:
$ echo '{"json":"obj"}' | python -mjson.tool
{
"json": "obj"
}
$ echo '{ 1.2:3.4}' | python -mjson.tool
Expecting property name: line 1 column 2 (char 2)
All argument patterns are:
-
piped json string | python -m json.toolwhich syntax checks then outputs the results to stdout -
python -m json.tool input_file.jsonwhich reads the path relative file and outputs the results -
python -m json.tool input_file.json output_file.jsononly difference here is that the output is directed to the specified file
My thoughts, this could be part of some sort of data validation check, looking for corrupted json static files.
Example
$ echo '{"a":123, "foo":"bar" }' | python -m json.tool && echo "IS valid" || echo "Is not valid"
{
"a": 123,
"foo": "bar"
}
IS valid
$ echo '{"a"1:123, "foo":"bar" }' | python -m json.tool && echo "IS valid" || echo "Is not valid"
Expecting : delimiter: line 1 column 4 (char 4)
Is not valid
Pingback: Python – batteries included - Refactored scope