Extract data from JSONs inside the CSV [closed]

守給你的承諾、 提交于 2019-12-14 00:08:52

问题


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

The data structure is like this

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:...

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?

Thanks a lot!


回答1:


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'])


来源:https://stackoverflow.com/questions/53059763/extract-data-from-jsons-inside-the-csv

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!