diff --git a/Lib/json/tool.py b/Lib/json/tool.py index 5932f4ecded7eb1..4b78d0f97be3791 100644 --- a/Lib/json/tool.py +++ b/Lib/json/tool.py @@ -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') @@ -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)) outfile.write('\n')