I have a file named source.json, the content is
{
"msg": "OK",
"result": {
"data": {
"articles": [
{
"idtArticle": "CF00002",
"promotionService": {
"bundleSales": [
{
"code": "201900001"
},
{
"code": "201900002"
}
]
}
},
{
"idtArticle": "CF00003",
"promotionService": {
"bundleSales": [
{
"code": "201900001"
},
{
"code": "201900003"
}
]
}
}
]
}
}
}
I have Python code as following:
import json
import jsonpath
json_source = 'source.json'
with open(json_source, encoding='utf-8') as f:
root = json.loads(f.read())
if __name__ == "__main__":
result = jsonpath.jsonpath(root, """$..articles[?(@.idtArticle == "CF00002")]""")
print(result)
The code works and I can get the article whose idtArticle is CF00002, but how to get the article list whose code(or one of the 2 codes) is 201900001?
Appreciate all the helps!