I'm trying to output JSON that has a list of mac addresses and a list of timestamps associated with each mac address. The output I'm looking for would look like this:
[
"B2:C7:23:10:A0":
[
"2014-04-04T21:30:46.348900800Z",
"2014-04-04T21:30:46.348900800Z",
"2014-04-04T21:30:46.348900800Z",
"2014-04-04T21:14:34.305303100Z",
"2014-04-04T21:14:34.285302000Z",
"2014-04-04T21:14:33.905280300Z"
],
"C7:99:12:F2:00":
[
"2014-04-09T22:18:43.162844700Z",
"2014-04-09T22:02:39.138705700Z",
"2014-04-09T22:02:37.429608000Z",
"2014-04-09T22:02:36.966581500Z",
"2014-04-09T22:02:36.966581500Z",
"2014-04-09T22:02:36.966581500Z",
],
]
Right now, the code I have makes the json above but with no keys (no mac addresses), only groups of timestamps.
list_count = 0
indices = []
mac_times_array = []
for foundMacAddress in found_mac_list:
indices = [i for i, x in enumerate(macAddressesTotal) if x == foundMacAddress]
grouped_times = []
for index in indices:
grouped_times.append(times[index])
mac_times_array.append(grouped_times)
stacked_array = [i for i in mac_times_array]
pprint.pprint(json.dumps(stacked_array))
So my question is, how do I add the mac addresses as keys? I've tried a bunch of different things but nothing is working.