I have created a python code that extracts jitter, latency, link, packet loss, timestamp from json file to csv file. However, inside this json file, there are multiple tests done (e.g. bronek 1, bronek 2, bronek 3, etc.) that under these testings have pair keys of jitter, latency, link, packet loss and timestamp.
I have pasted here a sample content of the json file and the python code.
How It can be extract these multiple testing from json file to csv with corresponding jitter, latency, link, packet loss and timestamp data?
python code:
import json
import csv
with open("/Users/olicaluag/Desktop/capture_for_Oliver.txt") as file:
data = json.load(file)
fname = “oli.csv”
with open(fname, “w”) as file:
csv_file = csv.writer(file)
csv_file.writerow([“Jitter”, “Latency”, “Link”, “Packetloss”, “Timestamp”])
for result in data[“result”]:
for data_item in result[“data”]:
for result in data_item[“response”][“results”]:
for item in result[“logs”]:
csv_file.writerow([item[“jitter”], item[“latency”], item[“link”], item[“packetloss”], item[“timestamp”]])
json file content:
“name”: “bronek 1”
},
{
“interface”: “port1”,
“logs”: [
{
“jitter”: 6.111866,
“latency”: 5.907633,
“link”: “up”,
“packetloss”: 0,
“timestamp”: 1624284672
},
{
“jitter”: 6.111166,
“latency”: 5.908467,
“link”: “up”,
“packetloss”: 0,
“timestamp”: 1624284672
},
“name”: “bronek 2”
},
{
“interface”: “port1”,
“logs”: [
{
“jitter”: 6.111866,
“latency”: 5.907633,
“link”: “up”,
“packetloss”: 0,
“timestamp”: 1624284672
},
{
“jitter”: 6.111166,
“latency”: 5.908467,
“link”: “up”,
“packetloss”: 0,
“timestamp”: 1624284672
},
“name”: “bronek 3”
},
{
“interface”: “port1”,
“logs”: [
{
“jitter”: 6.111866,
“latency”: 5.907633,
“link”: “up”,
“packetloss”: 0,
“timestamp”: 1624284672
},
{
“jitter”: 6.111166,
“latency”: 5.908467,
“link”: “up”,
“packetloss”: 0,
“timestamp”: 1624284672
},