I want to create a JSON file with Python. JSON structure looks like :
{
"index_pattern" : "all_packets"
"packets" : [
{
"packet_type" : "TCP"
"source_ip" : "192.168.0.2",
"destination_ip" : "192.168.0.114"
},
{
"packet_type" : "ICMP"
"source_ip" : "192.168.0.2",
"destination_ip" : "192.168.0.114"
}
]
}
Whenever I catch a packet with wireshark module, I want to add that packet to say myoutput.json file. The problem is, using something like
f = open("myoutput.json", "a")
f.write({
"packet_type" : "ICMP"
"source_ip" : "192.168.0.2",
"destination_ip" : "192.168.0.114"
})
is not suitable, because I do not have a graceful shutdown and I can not add necessary closing paranthesis to finish up the JSON. So I need to write in BETWEEN the packet array. What is the best way to achieve this.