U e5d @sjdZddlZddlZddlZddZedkrfz eWn.ek rdZzeej W5dZ[XYnXdS)aCommand-line tool to validate and pretty-print JSON Usage:: $ echo '{"json":"obj"}' | python -m json.tool { "json": "obj" } $ echo '{ 1.2:3.4}' | python -m json.tool Expecting property name enclosed in double quotes: line 1 column 3 (char 2) Nc Cs4d}d}tj||d}|jddtjdddtjd |jd dtjd ddd tjd |jd dddd|jddddd|}|j}|j }|j }|j }||~zJ|rdd|D}n t |f}|D] } t j| ||dd|dqWn,tk r} z t| W5d} ~ XYnXW5QRXW5QRXdS)Nzpython -m json.toolzZA simple command line interface for json module to validate and pretty-print JSON objects.)prog descriptioninfile?zutf-8)encodingz-a JSON file to be validated or pretty-printed)nargstypehelpdefaultoutfilewz%write the output of infile to outfilez --sort-keys store_trueFz5sort the output of dictionaries alphabetically by key)actionr r z --json-linesz&parse input using the jsonlines formatcss|]}t|VqdS)N)jsonloads).0liner!/usr/lib64/python3.8/json/tool.py ,szmain..) sort_keysindent )argparseArgumentParser add_argumentZFileTypesysstdinstdout parse_argsrr r json_linesrloaddumpwrite ValueError SystemExit) rrparserZoptionsrr rr!ZobjsobjerrrmainsD      r*__main__) __doc__rrrr*__name__BrokenPipeErrorexcexiterrnorrrrs $