Skip to content

Instantly share code, notes, and snippets.

@khoubyari
Last active August 5, 2017 04:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save khoubyari/578a6cb0e2ff06ded84d to your computer and use it in GitHub Desktop.
Save khoubyari/578a6cb0e2ff06ded84d to your computer and use it in GitHub Desktop.
Python: Call REST API and access the JSON results (no authentication)
# tested with Python 2.7.5
import json
import urllib2
api_url = "http://jsonplaceholder.typicode.com/users"
# API below returns an array of complex JSON objects
jsonobj = json.load(urllib2.urlopen(api_url))
# index into the array and access a sub-attribute like this:
print jsonobj[2]['company']['name']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment