Skip to content

Instantly share code, notes, and snippets.

@jcopps
Created July 12, 2020 13:41
Show Gist options
  • Save jcopps/b667d02620eace72b7dc893e6e53c378 to your computer and use it in GitHub Desktop.
Save jcopps/b667d02620eace72b7dc893e6e53c378 to your computer and use it in GitHub Desktop.
Python2.7 Make UTF-8 encoded JSON out of unicode(escaped)
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