[英]Json data parsing using python to get the specific headers value
I have a Following Json File format in which the data will be having Dynamic update.我有以下 Json 文件格式,其中数据将进行动态更新。 I have to parse the Json file using python with the following scenario我必须在以下情况下使用 python 解析 Json 文件
If the status: "PASS" , then the results of value should be maths,q1,q2如果status: "PASS" ,那么 value 的结果应该是maths,q1,q2
Kindly me with this scenario using python请使用 python 处理这种情况
{
"quiz": {
"sport": {
"q1": {
"question": "Which one is correct team name in NBA?",
"options": [
"New York Bulls",
"Los Angeles Kings",
"Golden State Warriros",
"Huston Rocket"
],
"answer": "Huston Rocket"
},
"status": "BLOCK"
},
"maths": {
"q1": {
"question": "5 + 7 = ?",
"options": [
"10",
"11",
"12",
"13"
],
"answer": "12"
},
"q2": {
"question": "12 - 8 = ?",
"options": [
"1",
"2",
"3",
"4"
],
"answer": "4"
},
"status": "PASS"
}
}
}
Hope below code gives you the expected output希望下面的代码能给你预期的 output
import json
file = open('data.json')
data = json.load(file)
keys = []
for i in data['quiz']:
if data['quiz'][i]['status'] != 'PASS':
keys.append(i)
for key in keys:
del data['quiz'][key]
print(data)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.