从CSV内的JSON中提取数据

从CSV内的JSON中提取数据

问题描述:

当我在一个CSV文件中包含多个JSON时,您能否建议从JSON中提取元素的最佳方法是什么?

Could you advise what would be the best way to extract an element from JSON when I have multiple JSONs in a CSV file?

数据结构是这样的

Line1: {"CreationTime":"2018-10-29T13:40:13","Id":"35127aae-a888-4665-6514-08d63da40e14","Operation":....,"IPaddress":"x.x.x.x"...} Line 2: {"CreationTime":"2018-10-29T13:41:13","Id":"35127aae-a888-4665-6514-08d63da40e14","Operation":....,"IPAddress":"x.x.x.x"...} ..... LineYY:...

Line1: {"CreationTime":"2018-10-29T13:40:13","Id":"35127aae-a888-4665-6514-08d63da40e14","Operation":....,"IPaddress":"x.x.x.x"...} Line 2: {"CreationTime":"2018-10-29T13:41:13","Id":"35127aae-a888-4665-6514-08d63da40e14","Operation":....,"IPAddress":"x.x.x.x"...} ..... LineYY:...

我的目标是从每行(即从每个json数组)中提取IPAddress值.最好的方法是什么?

My goal is to extract the IPAddress value from every line, that means from every json array. What would be the best way to do it?

非常感谢!

您可以使用json将每一行加载到字典中,然后访问IPAddress

You can use json to load each line into a dictionary and then access IPAddress

import json
ips = []
for line in data.readlines():
    row = json.loads(line)
    ips.append(row['IPAddress'])