Skip to content

Instantly share code, notes, and snippets.

@andrix
Created December 4, 2014 12:45
Show Gist options
  • Save andrix/3cc3ddef4044154fa0f2 to your computer and use it in GitHub Desktop.
Save andrix/3cc3ddef4044154fa0f2 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import sys, json
import codecs
import gzip
out = codecs.getwriter('utf8')(sys.stdout)
def _get_input():
if len(sys.argv) <= 1:
return sys.stdin
fname = sys.argv[1]
f = open(fname)
if fname.endswith(".gz"):
return gzip.GzipFile(fileobj=f)
return f
for l in _get_input():
out.write(json.dumps(json.loads(l), indent=3, ensure_ascii=False))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment