Created
July 12, 2020 13:41
-
-
Save jcopps/b667d02620eace72b7dc893e6e53c378 to your computer and use it in GitHub Desktop.
Python2.7 Make UTF-8 encoded JSON out of unicode(escaped)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
import codecs | |
import json | |
def make_utf_8_json(input_file, output_file): | |
content = json.loads(open(input_file, 'r').read()) | |
cc = json.dumps(content, indent=2, sort_keys=True, ensure_ascii=False) | |
file = codecs.open(output_file, "w", "utf-8") | |
file.write(cc) | |
file.close() | |
if __name__ == '__main__': | |
parser = argparse.ArgumentParser() | |
parser.add_argument("--file", "-f", type=str, required=True) | |
parser.add_argument("--out", "-o", type=str, default='out.json') | |
args = parser.parse_args() | |
make_utf_8_json(args.file, args.out) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment