Skip to content

Instantly share code, notes, and snippets.

@circa10a
Created September 27, 2019 02:09
Show Gist options
  • Save circa10a/7efcbfabd3907293241f2892b3e3d96f to your computer and use it in GitHub Desktop.
Save circa10a/7efcbfabd3907293241f2892b3e3d96f to your computer and use it in GitHub Desktop.
fetch json, convert to dict with urlllib
#!/usr/bin/env python3
import urllib.request as request
import json
url = "https://raw.githubusercontent.com/typicode/demo/master/db.json"
webURL = request.urlopen(url)
data = webURL.read()
encoding = webURL.info().get_content_charset('utf-8')
JSON_object = json.loads(data.decode(encoding))
print(JSON_object['posts'][0]['title'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment