Use the json module when working with json,write is called
So usually when call a API in Python then normal way is use Requests,and if need to to write to disk include the json module.
Example.
dump
when using json.So usually when call a API in Python then normal way is use Requests,and if need to to write to disk include the json module.
Example.
import json import requests time_line = requests.get('https://github.com/timeline.json') response = time_line.json() with open('time_line.json', 'w') as f: json.dump(response, f)Back:
with open("time_line.json", "r") as read_json: time_line = json.load(read_json) >>> time_line {'documentation_url': 'https://docs.github.com/v3/activity/events/#list-public-events', 'message': 'Hello there, wayfaring stranger. If you’re reading this then you ' 'probably didn’t see our blog post a couple of years back ' 'announcing that this API would go away: http://git.io/17AROg Fear ' 'not, you should be able to get what you need from the shiny new ' 'Events API instead.'} >>> time_line['documentation_url'] 'https://docs.github.com/v3/activity/events/#list-public-events'