Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../usr/lib64/python3..../json
File: tool.py
r"""Command-line tool to validate and pretty-print JSON
[0] Fix | Delete
[1] Fix | Delete
Usage::
[2] Fix | Delete
[3] Fix | Delete
$ echo '{"json":"obj"}' | python -m json.tool
[4] Fix | Delete
{
[5] Fix | Delete
"json": "obj"
[6] Fix | Delete
}
[7] Fix | Delete
$ echo '{ 1.2:3.4}' | python -m json.tool
[8] Fix | Delete
Expecting property name enclosed in double quotes: line 1 column 3 (char 2)
[9] Fix | Delete
[10] Fix | Delete
"""
[11] Fix | Delete
import argparse
[12] Fix | Delete
import collections
[13] Fix | Delete
import json
[14] Fix | Delete
import sys
[15] Fix | Delete
[16] Fix | Delete
[17] Fix | Delete
def main():
[18] Fix | Delete
prog = 'python -m json.tool'
[19] Fix | Delete
description = ('A simple command line interface for json module '
[20] Fix | Delete
'to validate and pretty-print JSON objects.')
[21] Fix | Delete
parser = argparse.ArgumentParser(prog=prog, description=description)
[22] Fix | Delete
parser.add_argument('infile', nargs='?', type=argparse.FileType(),
[23] Fix | Delete
help='a JSON file to be validated or pretty-printed')
[24] Fix | Delete
parser.add_argument('outfile', nargs='?', type=argparse.FileType('w'),
[25] Fix | Delete
help='write the output of infile to outfile')
[26] Fix | Delete
parser.add_argument('--sort-keys', action='store_true', default=False,
[27] Fix | Delete
help='sort the output of dictionaries alphabetically by key')
[28] Fix | Delete
options = parser.parse_args()
[29] Fix | Delete
[30] Fix | Delete
infile = options.infile or sys.stdin
[31] Fix | Delete
outfile = options.outfile or sys.stdout
[32] Fix | Delete
sort_keys = options.sort_keys
[33] Fix | Delete
with infile:
[34] Fix | Delete
try:
[35] Fix | Delete
if sort_keys:
[36] Fix | Delete
obj = json.load(infile)
[37] Fix | Delete
else:
[38] Fix | Delete
obj = json.load(infile,
[39] Fix | Delete
object_pairs_hook=collections.OrderedDict)
[40] Fix | Delete
except ValueError as e:
[41] Fix | Delete
raise SystemExit(e)
[42] Fix | Delete
with outfile:
[43] Fix | Delete
json.dump(obj, outfile, sort_keys=sort_keys, indent=4)
[44] Fix | Delete
outfile.write('\n')
[45] Fix | Delete
[46] Fix | Delete
[47] Fix | Delete
if __name__ == '__main__':
[48] Fix | Delete
main()
[49] Fix | Delete
[50] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function