Linux command
python-m-json.tool 命令
文件
复制后可按需替换文件名、目录或参数。
常用示例
Pretty print JSON
python -m json.tool [file.json]
Format from stdin
echo '{"key":"value"}' | python -m json.tool
Compact output
python -m json.tool --compact [file.json]
Sort keys
python -m json.tool --sort-keys [file.json]
说明
python -m json.tool is a built-in Python module that validates and pretty-prints JSON data. It reads JSON from a file argument or standard input, checks for syntax errors, and outputs a formatted version with proper indentation for readability. The tool is useful for quickly inspecting API responses, configuration files, or any JSON output piped from other commands. Options control key sorting, indentation depth, and compact output mode. Since it ships with Python's standard library, it requires no additional installation.
参数
- --sort-keys
- Sort object keys.
- --compact
- Compact output.
- --indent _N_
- Indentation level.
- --no-ensure-ascii
- Allow non-ASCII.
FAQ
What is the python-m-json.tool command used for?
python -m json.tool is a built-in Python module that validates and pretty-prints JSON data. It reads JSON from a file argument or standard input, checks for syntax errors, and outputs a formatted version with proper indentation for readability. The tool is useful for quickly inspecting API responses, configuration files, or any JSON output piped from other commands. Options control key sorting, indentation depth, and compact output mode. Since it ships with Python's standard library, it requires no additional installation.
How do I run a basic python-m-json.tool example?
Run `python -m json.tool [file.json]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does --sort-keys do in python-m-json.tool?
Sort object keys.