I'm receiving json responses in a loop, an unknown number of responses. The loop is stopped when a HTTP status code of anything other than 200 is returned. Each time through the loop, the response is added to a list.
data = []
x = 1
while True:
link = "http://sample.com/api/" + x
r = requests.get(link)
if r.status_code != 200:
break
data.append(json.loads(r.text))
Each json response in a batch will have the same keys, but I don't know if batch to batch they will be the same.
The list ends up like this:
[{'year': '2019', 'month': '1', 'day': '1', 'title': 'Some text', 'image': 'http://sample.com/image1.jpg', 'desc': 'some description of the content'},
{'year': '2019', 'month': '1', 'day': '2', 'title': 'New Title', 'image': 'http://sample.com/image2.jpg', 'desc': ''}]
How do I convert this to a single dataframe, using the keys in the response as the column names? If I can do it within the loop rather than converting after the fact, I'm fine with that option as well.