I'm trying to filter a Json array using Python based on multiple conditions. My Json is similar to this (no root name):
{
"id": "123455",
"outter": {
"inner": [
{
"nox": "abc:6666",
"code": "1329",
}
],
},
"topic": {
"reference": "excel"
},
"date1": "1990-07-28T03:52:44-04:00",
"finalDate": "1990-07-28T03:52:44-04:00"
}
{
"id": "123435",
"outter": {
"inner": [
{
"nox": "abc:6666",
"code": "9351",
}
],
},
"topic": {
"reference": "excel"
},
"date1": "1990-07-28T03:52:44-04:00",
"finalDate": "1995-07-28T03:52:44-04:00"
}
My goal is to filter based on 2 conditions and return all that match them.
1: outter --> inner --> code = 9351 AND
2: finalDate >= 1995
So far I can do this check separate with no problem with the following code:
data = pd.read_json('myFile.ndjson', lines = True)
for item in data['outter']:
for x in item['inner']:
if(x['code'] == '9351'):
found....
but not sure how to do both at the same time since I have to start the loop with either data['outter']
or data['finalDate']
and inside the loop I have only visibility to that element of the array, not the complete array.
Any help is appreciated, thanks!