Skip to content

Instantly share code, notes, and snippets.

@clowwindy
Created January 29, 2012 14:58
Show Gist options
  • Save clowwindy/1699170 to your computer and use it in GitHub Desktop.
Save clowwindy/1699170 to your computer and use it in GitHub Desktop.
json to Python object
input_str = "{'a':[{'b':'1','d':'3',},{'b':'2','d'='a'},{'b':'3','d':'4'}],'c':'1'}"
import json
class storage(object):
def __init__(self, dct):
self.__dict__ = dct
result = json.loads(input_str.replace("'",'"').replace("=", ":").replace(",}","}"), object_hook=storage)
print result.a[0].b
print result.a[1].d
print result.c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment