问题
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