I am trying to write a python script that will take a json object from a web page and write it to a flat file. There are ten lines in the flat file and three web pages. I have come to this code with the help of various online resources:
#!/usr/bin/python
import requests
import simplejson
r = requests.get('https://github.com/timeline.json')
c = r.content
j = simplejson.loads(c)
for item in j:
print item['repository']['name']
This code returns json objects from the github timeline events. The returned json objects are parsed and printed as a dictionary. I want to know is this a good way or is there a better way to do this?
Also, is there a way to send the json object to a python script that will update the flat file with the inputs from a webpage?
P.S Flat files are data files that contain records with no structured relationships. A normal .txt file with data.
requestscan decode json text for you: