-2

How do you filter a records in JSON Array using Python? Here's my Python code:

enter image description here

Sample Data Source: https://s3-eu-west-1.amazonaws.com/dwh-test-resources/recipes.json

In the "ingredients" i need to filter all records that contain bread. all string contain bread under the "ingredients" regardless if the string bread is upper case, lower case, plural or singular i should be able to filter it.

My python version is 3.

Dave
  • 19
  • 1
  • 1
  • 6

1 Answers1

0

Lets say:

data = [{...json you have}]

Now we will check:

res = []
for i in data:
    if 'bread' in i["ingredients"].lower():
        res.append(i)

or simply:

res = [i for i in data if 'bread' in i["ingredients"].lower()]
Joshua Varghese
  • 5,082
  • 1
  • 13
  • 34