Skip to content

Instantly share code, notes, and snippets.

@edhiley
Created October 15, 2015 10:37
Show Gist options
  • Save edhiley/c29b3e640f8d0fa8f592 to your computer and use it in GitHub Desktop.
Save edhiley/c29b3e640f8d0fa8f592 to your computer and use it in GitHub Desktop.
Converting json to msgpack

Run with

find . -type f -name '*.json' | xargs -n 1 python convert_json_to_msgpack.py
import fileinput
import msgpack
import sys
import json
file_lines = []
args = sys.argv[1]
for line in fileinput.input(args):
file_lines.append(line)
file_content = ''.join(file_lines)
file_dict = json.loads(file_content)
packed = msgpack.packb(file_dict)
output_file = args.replace('json', 'pack')
with open(output_file, 'w') as fw:
fw.write(packed)
exit(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment