Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Lib/json/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def main():
parser = argparse.ArgumentParser(prog=prog, description=description)
parser.add_argument('infile', nargs='?', type=argparse.FileType(),
help='a JSON file to be validated or pretty-printed')
parser.add_argument('outfile', nargs='?', type=argparse.FileType('w'),
parser.add_argument('outfile', nargs='?', type=argparse.FileType('w', encoding='utf-8'),
help='write the output of infile to outfile')
parser.add_argument('--sort-keys', action='store_true', default=False,
help='sort the output of dictionaries alphabetically by key')
Expand All @@ -37,7 +37,7 @@ def main():
except ValueError as e:
raise SystemExit(e)
with outfile:
json.dump(obj, outfile, sort_keys=sort_keys, indent=4)
outfile.write(json.dumps(obj,ensure_ascii=False,sort_keys=sort_keys, indent=4))

@pablogsal pablogsal Jun 14, 2018

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pep8: Please, separate every argument with space:

outfile.write(json.dumps(obj, ensure_ascii=False, sort_keys=sort_keys, indent=4)

outfile.write('\n')


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
when strings or files are encode with utf8 without bom, auto detect encoding
will fail. set default decoded type with utf-8 for most time