Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/AnonR/smanonr..../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 json
[13] Fix | Delete
import sys
[14] Fix | Delete
[15] Fix | Delete
[16] Fix | Delete
def main():
[17] Fix | Delete
prog = 'python -m json.tool'
[18] Fix | Delete
description = ('A simple command line interface for json module '
[19] Fix | Delete
'to validate and pretty-print JSON objects.')
[20] Fix | Delete
parser = argparse.ArgumentParser(prog=prog, description=description)
[21] Fix | Delete
parser.add_argument('infile', nargs='?',
[22] Fix | Delete
type=argparse.FileType(encoding="utf-8"),
[23] Fix | Delete
help='a JSON file to be validated or pretty-printed',
[24] Fix | Delete
default=sys.stdin)
[25] Fix | Delete
parser.add_argument('outfile', nargs='?',
[26] Fix | Delete
type=argparse.FileType('w', encoding="utf-8"),
[27] Fix | Delete
help='write the output of infile to outfile',
[28] Fix | Delete
default=sys.stdout)
[29] Fix | Delete
parser.add_argument('--sort-keys', action='store_true', default=False,
[30] Fix | Delete
help='sort the output of dictionaries alphabetically by key')
[31] Fix | Delete
parser.add_argument('--json-lines', action='store_true', default=False,
[32] Fix | Delete
help='parse input using the jsonlines format')
[33] Fix | Delete
options = parser.parse_args()
[34] Fix | Delete
[35] Fix | Delete
infile = options.infile
[36] Fix | Delete
outfile = options.outfile
[37] Fix | Delete
sort_keys = options.sort_keys
[38] Fix | Delete
json_lines = options.json_lines
[39] Fix | Delete
with infile, outfile:
[40] Fix | Delete
try:
[41] Fix | Delete
if json_lines:
[42] Fix | Delete
objs = (json.loads(line) for line in infile)
[43] Fix | Delete
else:
[44] Fix | Delete
objs = (json.load(infile), )
[45] Fix | Delete
for obj in objs:
[46] Fix | Delete
json.dump(obj, outfile, sort_keys=sort_keys, indent=4)
[47] Fix | Delete
outfile.write('\n')
[48] Fix | Delete
except ValueError as e:
[49] Fix | Delete
raise SystemExit(e)
[50] Fix | Delete
[51] Fix | Delete
[52] Fix | Delete
if __name__ == '__main__':
[53] Fix | Delete
try:
[54] Fix | Delete
main()
[55] Fix | Delete
except BrokenPipeError as exc:
[56] Fix | Delete
sys.exit(exc.errno)
[57] Fix | Delete
[58] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function