Python:将具有未知数量的密钥的JSON文件写入csv文件?

时间:2015-09-16 09:18:27

标签: python json csv dictionary nested

我有一个JSON文件,其中包含如下所示的行:

{"target":"http://103.15.234.121","http_status":302,"plugins":{"Country":{"string":["SINGAPORE"],"module":["SG"]},"Apache":{},"X-Powered-By":{"string":["PHP/5.5.24"]},"IP":{"string":["103.15.234.121"]},"PHP":{"version":["5.5.24"]},"RedirectLocation":{"s
    tring":["http://www.greenplanthydro.com.hk/"]},"HTTPServer":{"string":["Apache"]}}}
    {"target":"http://101.0.99.93","http_status":301,"plugins":{"Country":{"string":["AUSTRALIA"],"module":["AU"]},"Apache":{},"IP":{"string":["101.0.99.93"]},"Title":{"string":["301 Moved Permanently"]},"RedirectLocation":{"string":["http://www.101.0.99.93
    /403.shtml"]},"HTTPServer":{"string":["Apache"]}}}

我已经尝试逐行加载JSON对象,但我不知道如何将其转换为带有键作为标题的csv,主要是因为我不知道键的数量:

data_dict = []
file = open('../input_file','r')
for line in file:
    data_dict.append(json.loads(line))

有人可以帮忙吗?

0 个答案:

没有答案