If you want to iterate over both keys and values of the dictionary, do this:

for key, value in data.items():
    print(key, value)
Answer from Lior on Stack Overflow
🌐
Medium
medium.com › @sharath.ravi › python-function-to-extract-specific-key-value-pair-from-json-data-7c063ecb5a15
Python function to extract specific key value pair from json data. | by Sharath Ravi | Medium
April 6, 2023 - import json def extract_key_value(json_data, key): """Extracts a specific key-value pair from a JSON data""" data = json.loads(json_data) value = data.get(key) return value · In this example, the function extract_key_value takes two arguments: ...
Discussions

Json.loads only returns names but not the values
Hi everyone Tho I have lots of programming experience, I’m new to python and, of course, spyder. I have been following some youtube tutorial videos and now am trying out some api calls. I’m using Spyder 5.5.1 Here’s the code: import requests import json response = requests.get("https... More on discuss.python.org
🌐 discuss.python.org
0
March 19, 2024
JSON get value by keys path (string)
https://docs.python.org/3/library/json.html Load the JSON into a dict, and simply access it like you wrote with myJSON['generic']['lessgeneric']['store'] More on reddit.com
🌐 r/pythonhelp
4
2
March 26, 2022
Advice on how to iterate through JSON to find the first instance of a key value pair?
Is the index sorted in the json? If yes, you can just iterate over the codecs in the json and pick the first one that is audio. for stream in jsondata['streams']: if stream['codec_type']=="audio": cname = stream['codec_name'] break print(cname) More on reddit.com
🌐 r/learnpython
5
1
September 5, 2023
How to get values from all instances of key in JSON in Python - Stack Overflow
If I loop through the response and try to append the value, I get: TypeError: the JSON object must be str, bytes or bytearray, not list ... You should work through the Python tutorial if not done yet. More on stackoverflow.com
🌐 stackoverflow.com
🌐
W3Schools
w3schools.com › python › python_json.asp
Python JSON
The json.dumps() method has parameters to make it easier to read the result: Use the indent parameter to define the numbers of indents: ... You can also define the separators, default value is (", ", ": "), which means using a comma and a space ...
🌐
Python.org
discuss.python.org › python help
Json.loads only returns names but not the values - Python Help - Discussions on Python.org
March 19, 2024 - Hi everyone Tho I have lots of programming experience, I’m new to python and, of course, spyder. I have been following some youtube tutorial videos and now am trying out some api calls. I’m using Spyder 5.5.1 Here’s the code: import requests import json response = requests.get("https://jsonplaceholder.typicode.com/todos/1") print(response.status_code) print(response.text) res = json.loads(response.text) for data in res: print(data) Here’s the output: 200 ← status code is good Next i...
🌐
Zyte
zyte.com › home › blog › json parsing with python [practical guide]
JSON Parsing with Python [Practical Guide]
July 6, 2023 - After loading JSON data into Python, you can access specific data elements using the keys provided in the JSON structure. In JSON, data is typically stored in either an array or an object. To access data within a JSON array, you can use array indexing, while to access data within an object, you can use key-value pairs.
🌐
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" }, ...
🌐
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 - In this article, we will see how to perform the following JSON operations using Python. ... Let’s see each one by one. ... Let’s assume you received the following student, JSON. And you wanted to check if the percentage key is present or not in JSON data. if it is present directly to access its value instead of iterating the entire JSON.
Find elsewhere
🌐
Python Forum
python-forum.io › thread-37297.html
Trying to parse only 3 key values from json file
So im playing around with parsing a json file in python. Im able to read in the file and print it to the console, but now i want to extract 3 values from each 'section' not sure what the proper terminology is. Here is a example of the data structure...
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-program-to-extract-a-single-value-from-json-response
Python program to extract a single value from JSON response - GeeksforGeeks
July 23, 2025 - Import JSON from the modules. Open the JSON file in read-only mode using the Python with() function. Load the JSON data into a variable using the Python load() function. Now, get the value of keys in a variable.
🌐
DEV Community
dev.to › bluepaperbirds › get-all-keys-and-values-from-json-object-in-python-1b2d
Get all keys and values from json object in Python - DEV Community
January 12, 2021 - import json with open("test.json") as jsonFile: data = json.load(jsonFile) jsonData = data["emp_details"] for x in jsonData: keys = x.keys() print(keys) values = x.values() print(values) ...
🌐
Like Geeks
likegeeks.com › home › python › how to get json value by key in python
How To Get JSON Value by Key in Python
By converting the JSON string to a Python dictionary using json.loads(), you can retrieve any value by simply referencing its key. Using the get() method to access values provides a safer alternative to direct key access.
🌐
Real Python
realpython.com › python-json
Working With JSON Data in Python – Real Python
August 20, 2025 - When you deserialize a JSON file as a Python object, then you can interact with it natively—for example, by accessing the value of the "name" key with square bracket notation ([]).
🌐
Python
docs.python.org › 3 › library › json.html
json — JSON encoder and decoder
3 weeks ago - Serialize obj to a JSON formatted str using this conversion table. The arguments have the same meaning as in dump(). ... Keys in key/value pairs of JSON are always of the type str. When a dictionary is converted into JSON, all the keys of the dictionary are coerced to strings.
🌐
Reddit
reddit.com › r/pythonhelp › json get value by keys path (string)
r/pythonhelp on Reddit: JSON get value by keys path (string)
March 26, 2022 -

I have a JSON file that I want to automatically check specific values, like myJSON['generic']['lessgeneric']['store'] should be equal to 100,

was thinking of doing something like this:

checks = [ {'name':'field_1','path':'myJSON['generic']['lessgeneric']['store']','value':'100'} ]

but I have no clue how to convert the string "myJSON['generic']['lessgeneric']['store']" into it's value, any help would be appreciated!

edit: how I solved it

path = "generic>lessgeneric>store"
value = 100
def check_value(path,value):
    temp_json = my_json
    for key in path.split(">"):
        temp_json = temp_json[key]
    if temp_json == value:
        pass
🌐
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!!!

🌐
freeCodeCamp
freecodecamp.org › news › how-to-parse-json-in-python-with-examples
How to Parse JSON in Python – A Complete Guide With Examples
October 29, 2025 - You'll use it to convert JSON strings into Python dictionaries and lists that you can manipulate with familiar syntax, and then convert your Python data structures back into JSON when you need to send data to an API or save it to a file. Beyond basic parsing, you'll often need to handle nested structures, validate data integrity, manage, and transform data formats. This guide covers practical JSON parsing techniques you can use in your projects right away. Let’s get started! ... JSON represents data using a simple syntax with six data types: objects (key-value pairs), arrays, strings, numbers, Booleans, and null.
🌐
Robotastemtraining
robotastemtraining.com › read › how-do-you-get-all-values-by-key-with-json-and-python
How Do You Get All Values by Key with JSON and Python?
import json # Load JSON data json_data = ''' { "name": "John", "age": 30, "city": "New York", "children": [ { "name": "Anna", "age": 10 }, { "name": "Alex", "age": 7 } ] } ''' data = json.loads(json_data) # Function to get all values by key def get_values_by_key(data, key): values = [] def ...
🌐
LabEx
labex.io › tutorials › python-how-to-access-nested-keys-in-a-python-json-object-395034
How to access nested keys in a Python JSON object | LabEx
Catch KeyError (missing dictionary key) and TypeError (attempting to access a key on a non-dictionary) ... The get() method approach is generally preferred for its readability and conciseness when dealing with nested JSON structures. It allows you to provide default values at each level of nesting.