Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(164404)

Delta Between Two Patch Sets: Lib/json/tool.py

Issue 16333: Trailing whitespace in json dump when using indent
Left Patch Set: Created 7 years ago
Right Patch Set: Created 7 years ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « Doc/library/json.rst ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 r"""Command-line tool to validate and pretty-print JSON 1 r"""Command-line tool to validate and pretty-print JSON
2 2
3 Usage:: 3 Usage::
4 4
5 $ echo '{"json":"obj"}' | python -m json.tool 5 $ echo '{"json":"obj"}' | python -m json.tool
6 { 6 {
7 "json": "obj" 7 "json": "obj"
8 } 8 }
9 $ echo '{ 1.2:3.4}' | python -m json.tool 9 $ echo '{ 1.2:3.4}' | python -m json.tool
10 Expecting property name enclosed in double quotes: line 1 column 2 (char 2) 10 Expecting property name enclosed in double quotes: line 1 column 2 (char 2)
(...skipping 11 matching lines...) Expand all
22 outfile = sys.stdout 22 outfile = sys.stdout
23 elif len(sys.argv) == 3: 23 elif len(sys.argv) == 3:
24 infile = open(sys.argv[1], 'rb') 24 infile = open(sys.argv[1], 'rb')
25 outfile = open(sys.argv[2], 'wb') 25 outfile = open(sys.argv[2], 'wb')
26 else: 26 else:
27 raise SystemExit(sys.argv[0] + " [infile [outfile]]") 27 raise SystemExit(sys.argv[0] + " [infile [outfile]]")
28 try: 28 try:
29 obj = json.load(infile) 29 obj = json.load(infile)
30 except ValueError as e: 30 except ValueError as e:
31 raise SystemExit(e) 31 raise SystemExit(e)
32 json.dump(obj, outfile, sort_keys=True, indent=4) 32 json.dump(obj, outfile, sort_keys=True, indent=4, separators=(',', ': '))
33 outfile.write('\n') 33 outfile.write('\n')
34 34
35 35
36 if __name__ == '__main__': 36 if __name__ == '__main__':
37 main() 37 main()
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+