我从 api 中提取 JSON 格式的数据,源 JSON 格式如下所示:
源样本:
{
"hasMore": false,
"data": [
{
"id": "ne0OyNrH0u1X7zHSRcxItg",
"name": "Start Here",
"createdDate": "2021-01-06T18:59:54.923000Z",
"createdById": "kIU0GuRk43lLi8pq16VIgQ",
"updatedDate": "2021-01-25T19:41:21.231510Z",
"updatedById": "utcXmeXjBb7vyAzMClxD5g",
"status": "Completed",
"templateId": "npt5sit7R6AqrrXNlh9FMQ",
"completedDate": "2021-01-25T19:41:21.374000Z",
"completedById": "utcXmeXjBb7vyAzMClxD5g",
"dueDate": null
},
{
"id": "soYwhmamfpFPv1kWesZKJg",
"name": "Test Well No. 3D",
"createdDate": "2021-02-09T20:27:04.307000Z",
"createdById": "i6Doi4vke7SefvGbyGpN3A",
"updatedDate": "2021-02-09T20:27:04.307000Z",
"updatedById": "i6Doi4vke7SefvGbyGpN3A",
"status": "Active",
"templateId": "nDEwm4HENbpWfmpotstPKw",
"completedDate": null,
"completedById": null,
"dueDate": null
}
],
"nextPageId": "soYwhmamfpFPv1kWesZKJg",
"nextPageUpdatedDate": "2021-02-09T20:27:04.307000Z"
}
目标样本:
id,name,createdDate,createdById,updatedDate,updatedById,status,templateId,completedDate,completedById,dueDate
"ne0OyNrH0u1X7zHSRcxItg","Start Here","2021-01-06T18:59:54.923000Z","kIU0GuRk43lLi8pq16VIgQ","2021-01-25T19:41:21.231510Z","utcXmeXjBb7vyAzMClxD5g","Completed","npt5sit7R6AqrrXNlh9FMQ","2021-01-25T19:41:21.374000Z","utcXmeXjBb7vyAzMClxD5g",
"udvF3_5fRO1wsPA-4XBDuw","Test Well No. 1D","2021-01-25T14:36:34.270000Z","i6Doi4vke7SefvGbyGpN3A","2021-02-03T15:00:48.923031Z","i6Doi4vke7SefvGbyGpN3A","Active","nDEwm4HENbpWfmpotstPKw",,,
json_data = response.json()['data']
for each_rec in json_data:
if count == 0:
# Writing headers of CSV file
header = each_rec.keys()
csv_writer.writerow(header)
count += 1
else:
csv_writer.writerow(each_rec.values())
response.close
如何在插入文件的每一行中包含“hasMore”、“nextPageId”、“nextPageUpdatedDate”?
谢谢