Here is a one-liner example for searching:

aaa = {
  "success":True,
  "data":
  {
    "array":
    [
      {
        "id":"1","name":"Value1"
      },
      {
        "id":"2","name":"Value2"
      }
    ]
  }
}

[a['name'] for a in aaa['data']['array'] if a['id']=='1']

This will return all the found cases, or an empty array if nothing is found

Answer from Roee Anuar on Stack Overflow
🌐
PYnative
pynative.com › home › python › json › python check if key exists in json and iterate the json array
Python Check if key exists in JSON and iterate the JSON array
May 14, 2021 - Check if the key exists or not in JSON using Python. Check if there is a value for a key. Return default value if the key is missing in JSON. Iterate JSON array in Python.
Discussions

The Fastest method to find element in JSON (Python) - Stack Overflow
@ArpitSolanki I didn't find anything about speed of parsing json. So I want to ask it here. Do you have something against to this? ... def function(json_object, name): for dict in json_object: if dict['name'] == name: return dict['price'] If you are sure that there are no duplicate names, an even more effective (and pythonic... More on stackoverflow.com
🌐 stackoverflow.com
Accessing data from a json array in python - Stack Overflow
Usually the json will be a string and you will try and deserialise it into a object graph (which in python are typically are made up of maps and arrays). More on stackoverflow.com
🌐 stackoverflow.com
Find a value of Key in Json Array - Python - Stack Overflow
I have a Json array which has key value pairs. I want to get value of a particular key in the list. I don't know at what position the key will be in the array so I cant use the index in the array. ... More on stackoverflow.com
🌐 stackoverflow.com
Find a value in JSON using Python - Stack Overflow
I’ve previously succeeded in parsing data from a JSON file, but now I’m facing a problem with the function I want to achieve. I have a list of names, identification numbers and birthdate in a JSON.... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Linux Hint
linuxhint.com › search_json_python
How to search for data in JSON using python – Linux Hint
In the following script, a JSON array named jsondata is defined. A particular value of a key will be searched here and if the value exists then the value of another related key will be printed as output. search_price() function is defined here take the value of the name key that will be searched in the JSON data and it will print the value of the corresponding unit_price key. #!/usr/bin/env python3 # Import json module import json # Define json variable jsondata = """[ { "name":"Pen", "unit_price":5 }, { "name":"Eraser", "unit_price":3 }, { "name":"Pencil", "unit_price":10 }, { "name":"White p
🌐
Temboo
temboo.com › python › parsing-json
Parsing JSON in Python
To do this, you'll use the following square bracket syntax for specifying the items array, then the first item in that array (at index 0), and finally the snippet object within the first item in the array: 7 To finish up, we assigned the title and description properties that are nested within the snippet object to local variables. title = data["items"][0]["snippet"]["title"] description = data["items"][0]["snippet"]["description"] 8All finished! Run the code to try it out. You should see the title of your first YouTube Search result in the console. Now you should to able to parse all sorts of JSON responses with our Python SDK. You can find lots of JSON responses to flex your parsing skills on in our Library.
🌐
Python Guides
pythonguides.com › json-data-in-python
How To Get Values From A JSON Array In Python?
November 29, 2024 - Then, for each city, we access the landmarks array and use another for loop to iterate over each landmark. The output will be: City: New York City Landmarks: - Statue of Liberty - Central Park - Empire State Building --- City: Los Angeles Landmarks: - Hollywood Sign - Griffith Observatory - Venice Beach --- ... In some cases, you may want to filter the JSON data based on certain conditions. Python provides several ways to filter arrays, such as using conditional statements or the filter() function.
🌐
Medium
medium.com › @artijs › searching-values-in-json-using-python-a4badf5fa76a
Searching values in JSON using Python | by Arthur J | Medium
December 2, 2023 - A json file is made up of key-value pair. We shall use JSON module in python to understand and search inside a file.
Find elsewhere
Top answer
1 of 2
2

w = y['filters']['filterB'] doesn't work because y['filters'] is a list and not dict.

The answer to your question depends on how you want to handle the case of multiple dictionaries inside filters list that have filterB key.

import json
x = '{"filters":[{"filterA":"All"},{"filterB":"val1"}]}'
y = json.loads(x)

# all filterB values
filter_b_values = [x['filterB'] for x in y['filters'] if 'filterB' in x.keys()] 

# take first filterB value or None if no values
w = filter_b_values[0] if filter_b_values else None

2 of 2
2

The source of your data (json) has nothing to do with what you want, which is to find the dictionary in y['filters'] that contains a key called filterB. To do this, you need to iterate over the list and look for the item that fulfils this condition.

w = None
for item in y['filters']:
    if 'filterB' in item:
        w = item['filterB']
        break

print(w) # val1

Alternatively, you could join all dictionaries into a single dictionary and use that like you originally tried

all_dict = dict()
for item in y['filters']:
    all_dict.update(item)

# Replace the list of dicts with the dict
y['filters'] = all_dict

w = y['filters']['filterB']
print(w) # val1

If you have multiple dictionaries in the list that fulfil this condition and you want w to be a list of all these values, you could do:

y = {"filters":[{"filterA":"All"},{"filterB":"val1"},{"filterB":"val2"}]}
all_w = list()
for item in y['filters']:
    if 'filterB' in item:
        all_w.append(item['filterB'])

Or, as a list-comprehension:

all_w = [item['filterB'] for item in y['filters'] if 'filterB' in item]
print(all_w) # ['val1', 'val2']

Note that a list comprehension is just syntactic sugar for an iteration that creates a list. You aren't avoiding any looping by writing a regular loop as a list comprehension

🌐
Chilkat
chilkatsoft.com › refdoc › pythonJsonArrayRef.html
JsonArray Python Reference Documentation
Appends the array items contained in jarr. Returns True for success, False for failure. ... Returns the JSON array found at index, where indexing starts at 0.
🌐
W3Schools
w3schools.com › python › python_json.asp
Python JSON
Arrays Code Challenge Python Iterators · Iterators Code Challenge Python Modules · Modules Code Challenge Python Dates · Dates Code Challenge Python Math · Math Code Challenge Python JSON · JSON Code Challenge Python RegEx · RegEx Code Challenge Python PIP Python Try...Except · Try...Except Code Challenge Python String Formatting · String Formatting Code Challenge Python None · None Code Challenge Python User Input Python VirtualEnv ·
🌐
Zyte
zyte.com › home › blog › json parsing with python [practical guide]
A Practical Guide to JSON Parsing with Python
July 6, 2023 - For example, you can use JMESPath to filter a list of objects based on a specific value or to extract specific parts of an object and transform them into a new structure. Let's say we have a JSON array of car objects, each containing information such as the car's make, model, year and price:
🌐
Real Python
realpython.com › python-json
Working With JSON Data in Python – Real Python
August 20, 2025 - For example, you can include an object as the value of an object. Also, you’re free to use any other allowed value as an item in a JSON array. As a Python developer, you may need to pay extra attention to the Boolean values.
🌐
Reddit
reddit.com › r/learnpython › advice on how to iterate through json to find the first instance of a key value pair?
r/learnpython on Reddit: Advice on how to iterate through JSON to find the first instance of a key value pair?
September 5, 2023 -

I have an undesirable JSON object that I can't modify:

{
"programs": [

],
"streams": [
    {
        "index": 0,
        "codec_name": "hevc",
        "codec_type": "video"
    },
    {
        "index": 1,
        "codec_name": "aac",
        "codec_type": "audio"
    },
    {
        "index": 2,
        "codec_name": "opus",
        "codec_type": "audio"
    },
    {
        "index": 3,
        "codec_name": "ac3",
        "codec_type": "audio"
    },
    {
        "index": 4,
        "codec_name": "ass",
        "codec_type": "subtitle"
    },
    {
        "index": 5,
        "codec_name": "ttf",
        "codec_type": "attachment"
       }
       ]
}

This is psudo json from the very real output of ffprobe -loglevel error -show_entries format:stream=index,stream,codec_type,codec_name -of json FILENAME

I need to get the first codec_name from the lowest index of the codec_type: audio.

In this case, index 1, 2, and 3 are all of codec_type: audio, so the lowest index/first instance would be 1 and my codec_name would be aac.

Any ideas on how to move forward on a problem like this? I can't seem to find any stackoverflow threads with anything similar.

----------------------------

EDIT, solution here: https://www.reddit.com/r/learnpython/comments/16af8zf/comment/jz74hc9/?utm_source=share&utm_medium=web2x&context=3

Thank you u/shiftybyte, u/djshadesuk!!!

🌐
Quora
quora.com › How-do-you-get-all-values-by-key-with-JSON-and-Python
How to get all values by key with JSON and Python - Quora
Answer: You can use the [code ]json[/code] library in Python to get values associated with a key in a JSON object. Here's an example: [code]import json # sample JSON data data = """ { "employees": [ { "firstName": "John", "lastName": "Doe" }, ...
🌐
GeeksforGeeks
geeksforgeeks.org › working-with-json-data-in-python
Working With JSON Data in Python | GeeksforGeeks
June 3, 2022 - The values in a JSON array must be separated by commas and enclosed in squares in brackets []. In this article, we will learn how we can loop through a JSON array in Python.