Не уверен, пытаюсь ли я достичь невозможного?У меня есть эта строка JSON:
dot= [{"type": 1, "date": "2018-12-02T00:40:03.2186792+00:00", "device":
[{"id": "20165cf4e596", "deviceName": "17", "records": [{"timestamp": "2018-
12-02T00:40:00.499+00:00", "grp": "undefined", "val": 887}]}, {"id":
"5f401a6a6f66", "deviceName": "18", "records": [{"timestamp": "2018-12-
02T00:42:00.499+00:00", "grp": "undefined", "val": 1063}, {"timestamp":
"2018-12-02T00:41:00.498+00:00", "grp": "undefined", "val": 907}]}, {"id":
"569bb0147a72", "deviceName": "19", "records": [{"timestamp": "2018-12-
02T00:44:00.499+00:00", "grp": "undefined", "val": 817}, {"timestamp":
"2018-12-02T00:43:00.498+00:00", "grp": "undefined", "val": 1383}]}, {"id":
"ef829aa3", "deviceName": "2", "records": [{"timestamp": "2018-12-
02T00:46:00.499+00:00", "grp": "undefined", "val": 1173}]}, {"id":
"388ae8f2fa64", "deviceName": "17", "records": [{"timestamp": "2018-12-
02T00:41:00.499+00:00", "grp": "undefined", "val": 866}, {"timestamp":
"2018-12-02T00:32:00.492+00:00", "grp": "undefined", "val": 1080}]}, {"id":
"01f874b30b55", "deviceName": "19", "records": [{"timestamp": "2018-12-
02T00:43:00.499+00:00", "grp": "undefined", "val": 1050}, {"timestamp":
"2018-12-02T00:42:00.498+00:00", "grp": "undefined", "val": 1084}]}]}]
И я хочу добиться следующего:
[{'id': '20165cf4e596','deviceName': '17','timestamp': '2018-12-
02T00:40:00.499+00:00','grp': 'undefined','val': 887},
{'id': '5f401a6a6f66','deviceName': '18','timestamp': '2018-12-
02T00:42:00.499+00:00','grp': 'undefined','val': 1063},
{'id': '5f401a6a6f66','deviceName': '18','timestamp': '2018-12-
02T00:41:00.498+00:00','grp': 'undefined','val': 907},...]
Я использовал следующий код:
for i in dot:
for k in i['device']:
d2= [[{l:m},{'value':v}] for l,m in k.items() for p in m if
isinstance(p,list) for v in p]
print(d2)
И получил пустойсписки:
[]
[]
[]
[]
Заранее спасибо