Skip to content

Instantly share code, notes, and snippets.

@rameshshihora
Forked from mpasternacki/json2path.py
Created November 22, 2015 05:44
Show Gist options
  • Save rameshshihora/e1a38906a3a13f9c85aa to your computer and use it in GitHub Desktop.
Save rameshshihora/e1a38906a3a13f9c85aa to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import json
import sys
def pp(vv, prefix='$'):
if isinstance(vv, (list,tuple)):
for i, v in enumerate(vv):
pp(v, "{0}[{1}]".format(prefix, i))
elif isinstance(vv, dict):
for k,v in sorted(vv.items()):
pp(v, "{0}.{1}".format(prefix, k))
else:
print '{0} = {1}'.format(prefix, json.dumps(vv))
pp(json.load(sys.stdin))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment