a ;`n @sldZddlZddlZddlZddZedkrhz eWn0eyfZzeej WYdZ[n dZ[00dS)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 Csd}d}tj||d}|jddtjdddtjd |jd dtjd ddd tjd |jd dddd|jddddd|jddddd|}|jddtdd|jdddd d!d"|jd#dddd$d"|jd%dd&d'| }|j |j |j d(}|j rd|d<d)|d*<|j}|j}zR|jr8d+d,|D}n t|f}|D]$} tj| |fi||d-qHWn.ty} zt| WYd} ~ n d} ~ 00Wdn1s0YWdn1s0YdS).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--no-ensure-ascii ensure_asciiZ store_falsez(disable escaping of non-ASCII characters)destrr z --json-linesznparse input using the JSON Lines format. Use with --no-indent or --compact to produce valid JSON Lines output.z--indentzJseparate items with newlines and use this number of spaces for indentation)r rr z--tabZ store_constindent z9separate items with newlines and use tabs for indentation)rrZconstr z --no-indentz/separate items with spaces rather than newlinesz --compactz1suppress all whitespace separation (most compact))rr ) sort_keysrr),:Z separatorscss|]}t|VqdS)N)jsonloads).0liner/usr/lib/python3.9/json/tool.py @zmain.. )argparseArgumentParser add_argumentZFileTypesysstdinstdoutZadd_mutually_exclusive_groupint parse_argsrrrZcompactrr Z json_linesrloaddumpwrite ValueError SystemExit) rrparsergroupZoptionsZ dump_argsrr Zobjsobjerrrmainsl         r1__main__) __doc__r rr#r1__name__BrokenPipeErrorexcexiterrnorrrrs 8