我有一个来自json响应的3个数据集,并且必须从我的端部合并和重构它们。 3个数据集的密钥和长度相同。
dev.json
[
{
"result":{
"duration":0.0,
"status":"passed"
}
},
{
"result":{
"duration":0.0,
"status":"passed"
}
}
]
qa.json
[
{
"result":{
"duration":0.0,
"status":"passed"
}
},
{
"result":{
"duration":0.0,
"status":"passed"
}
}
]
prod.json
[
{
"result":{
"duration":0.0,
"status":"failed"
}
},
{
"result":{
"duration":0.0,
"status":"failed"
}
}
]
我想将它们重组为以下格式:
[
{
"result":{
"qa":"passed",
"dev":"passed",
"prod":"failed"
}
},
{
"result":{
"qa":"passed",
"dev":"passed",
"prod":"failed"
}
}
]
到目前为止我做了什么:
with open('qa.json') as data_file:
qa = json.load(data_file)
with open('dev.json') as data_file:
dev = json.load(data_file)
with open('prod.json') as data_file:
prod= json.load(data_file)
#I'm not good with python but this is what i've gotten so far and obviously incorrect
json_list = [dict(list(x[0].items()) + list(x[1].items() + list(x[3].items())) for x in zip(qa,dev,prod)]
来自javascript背景,我正试图找出如何遍历列表对象并分配新密钥