I have a text file with four columns: time serial domain server
the contents of the text file are as follows:
15 14 google.com 8.8.8.8
19 45 google.com 8.8.4.4
98 76 google.com 208.67.222.222
20 23 intuit.com 8.8.8.8
45 89 intuit.com 8.8.4.4
43 21 intuit.com 208.67.222.222
78 14 google.com 8.8.8.8
92 76 google.com 8.8.4.4
64 54 google.com 208.67.222.222
91 18 intuit.com 8.8.8.8
93 74 intuit.com 8.8.4.4
65 59 intuit.com 208.67.222.222
What would be the best way to read this file and create a list of dict as follows:
[{"server":"8.8.8.8",
"domains":[{"google.com":[{"time":15, "serial":14}, {"time":78, "serial":14}]},
{"intuit.com":[{"time":20, "serial":23}, {"time":91, "serial":18}]}
]
},
{"server":"8.8.4.4",
"domains":[{"google.com":[{"time":19, "serial":45}, {"time":92, "serial":76}]},
{"intuit.com":[{"time":45, "serial":89}, {"time":93, "serial":74}]}
]
},
{"server":"206.67.222.222",
"domains":[{"google.com":[{"time":98, "serial":76}, {"time":64, "serial":54}]},
{"intuit.com":[{"time":43, "serial":21}, {"time":65, "serial":59}]}
]
}]
The order of the rows could change but the columns always remain the same.