How to parse json in bash or pass curl output to python script -


i'm looking find way have pretty print of curl's output in json. wrote short python script purpose, won't work pipe don't want use subprocesses , run curl them:

so python:

#!/usr/bin/python  import simplejson pprint import pprint import sys print pprint(simplejson.loads(sys.argv[1])) 

and json information is:

{"response": {"utilization": {"eic": [{"date": "2012.03.06", "usage": []}, {"date": "2012.03.07", "usage": [{"srvcode": "svc302", "upload": 267547188, "api-calls": {"filegetinfo": 30, "getuserstoragequota": 0, "setuserstoragequota": 0, "fileuploadflashinit": 31, "getapisessionuser": 0, "setfileaccesscontrol": 0, "filegetpreviewurl": 0, "filestartmultipartupload": 0, "getservicequota": 0, "filegetpreviewurlsforbunch": 10, "xcodinggetstreamurl": 0, "getsessiontimelimit": 0, "filegetcoversurlsforbunch": 27, "makepreviews": 0, "setservicequota": 0, "getapisessiontrusted": 3, "getfileaccesscontrol": 0, "xcodinggetformats": 0, "getquotanotificationemail": 0, "filegetdownloadurl": 0, "xcodinggetstreaminfo": 0, "fileuploaddone": 30, "getlocalserviceutilization": 9, "getserviceutilization": 0, "filedelete": 19, "setsessiontimelimit": 0, "filegetmultipartuploadurl": 0, "fileuploadinit": 0, "extractfilemetadata": 30, "setquotanotificationemail": 0}, "average-storage": 3801210959.4961309, "download": 0, "transcoding": 0}]}]}}} 

using json.tool shell validate , pretty-print:

$ echo '{"json":"obj"}' | python -mjson.tool {     "json": "obj" } 

Comments

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

media player - Android: mediaplayer went away with unhandled events -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -