Skip to content

Instantly share code, notes, and snippets.

@fmasanori
Last active December 17, 2015 13:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save fmasanori/5620404 to your computer and use it in GitHub Desktop.
Save fmasanori/5620404 to your computer and use it in GitHub Desktop.
json object_hook
import urllib.request
import json
from pprint import pprint
class Dic42(dict):
def __missing__(self, key):
return '42'
url = 'https://graph.facebook.com/fmasanori'
resp = urllib.request.urlopen(url).read()
data = json.loads(resp.decode('utf-8'),
object_hook = Dic42)
pprint (data)
print ()
print ('Ultimate answer:', data['Ultimate answer'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment