Persistence and Serialization Modules

json.tool

Supplies the command-line formatter and parser for JSON. Run python -m json.tool to read stdin or an input file and write formatted JSON. Invalid syntax produces an error; successful parsing is not schema validation and Python’s default JSON parser accepts some nonstandard values. The equivalent formatting API can be used without spawning a command.

Formal Syntax & Structure

python syntaxpython
python -m json.tool [infile] [outfile]

Return Value

command-line output

Formatted JSON text on stdout or in the selected output file; invalid input reports an error.

Working Example

Example Snippetpython
import jsonprint(json.dumps(json.loads('{"count":2}'), indent=2))
Python Reference