python JSONライブラリの正式なドキュメントを見ると、の呼び出しがでjson.toolあることがわかりますpython -mjson.tool。これは、Pythonインストールのディレクトリのtool.py下のファイルにあるプログラムjson、またはPythonインストール__init__.pyのtoolディレクトリの下のファイルにあることを示しjsonます。
ファイルは実際には2つのうちの前者であり、そのmain()機能は簡単に分析できる20行未満のコードです。
- 引数がない場合、パイプとして機能します:JSON入力およびJSON出力
- JSON入力ファイルとして使用される引数が1つある場合、stdoutへの出力
- 2つの引数があり、1つ目はJSON入力ファイル、2つ目はJSON出力ファイル
さらにパラメーターを指定すると、実際に使用法が表示されます。
$ python -m json.tool a b c
/opt/python/2.7.11/lib/python2.7/json/tool.py [infile [outfile]]
これは、ツールの2.7バージョン用です。3.5.1バージョンには追加のパラメーターがあり、以下を使用するとパラメーターが表示されます-h。
$ python -m json.tool -h
usage: python -m json.tool [-h] [--sort-keys] [infile] [outfile]
A simple command line interface for json module to validate and pretty-print
JSON objects.
positional arguments:
  infile       a JSON file to be validated or pretty-printed
  outfile      write the output of infile to outfile
optional arguments:
  -h, --help   show this help message and exit
  --sort-keys  sort the output of dictionaries alphabetically by key