HTTP requests and JSON parsing in Python

Viewed 829963
8 Answers

requests has built-in .json() method

import requests
requests.get(url).json()

just import requests and use from json() method :

source = requests.get("url").json()
print(source)

OR you can use this :

import json,urllib.request
data = urllib.request.urlopen("url").read()
output = json.loads(data)
print (output)

Also for pretty Json on console:

 json.dumps(response.json(), indent=2)

possible to use dumps with indent. (Please import json)

Related