Skip to content

Instantly share code, notes, and snippets.

@allanjos
Last active November 5, 2018 17:50
Show Gist options
  • Save allanjos/f7dd3b6ac7afcb8d5df65bc22f5c9ab8 to your computer and use it in GitHub Desktop.
Save allanjos/f7dd3b6ac7afcb8d5df65bc22f5c9ab8 to your computer and use it in GitHub Desktop.
Python / JSON / Hash / Array
import json
jsonStr = '[{"one" : "1", "two" : "2", "three" : "3"}]';
print "Parsing json " + jsonStr
listData = json.loads(jsonStr)
print "Direct access:"
print "\tone = " + listData[0]['one']
print "\ttwo = " + listData[0]['two']
print "\tthree = " + listData[0]['three']
print "Iteration over hash:"
for hashDataElement in listData:
for key in hashDataElement:
print "\t" + key + ": " + hashDataElement[key]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment