将JSON输出转换为CSV以获取AWS API输出“ client.describe_trusted_advisor_check_result”

时间:2019-01-31 13:20:44

标签: python json amazon-web-services csv

将JSON输出转换为CSV以用于AWS API输出client.describe_trusted_advisor_check_result

我想用Python中的脚本将输出JSON转换为CSV。我得到的JSON输出是嵌套的。

`

import json
import csv

with open('idcheck.json', 'r') as f:
    json_dict = json.load(f)

# Open new CSV file
with open("output5.csv", "w") as csv_file:
    writer = csv.writer(csv_file)

    # Write CSV headers

    # Write data to CSV for each image
    images_data = json_dict['result']['flaggedResources']
    for image in images_data:
        writer.writerow([images_data['status'],
             images_data['region'],
             images_data['resourceId'],
             images_data['isSuppressed']])

`

0 个答案:

没有答案