testdata.json
{"foo":"bar", "baz":1, "a":2}
jsonstdio.py
import sys
import json
def getjson(jd):
jsondata = json.loads(jd)
print "JSON Data: "
print repr(jsondata)
def main():
stdin = sys.stdin.read()
getjson(stdin)
if __name__=="__main__":
main()
How to run:
python jsonstdio.py < testdata.json
2 comments:
How would you access the "foo" object's value from the jsondata variable? How would you iterate over the keys present in jsondata?
I don't know python much, see...
Dan, it loads into a dictionary, and you get iterate with standard dictionary methods.
Post a Comment