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
๐ŸŒ
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 - Using load function json file, this let me keep it into a variable called data. ... Then you have a Python object. Now you can get the keys and values. The code below depends on what your json file looks like.
๐ŸŒ
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.
๐ŸŒ
Python Guides
pythonguides.com โ€บ json-data-in-python
How To Get Values From A JSON Array In Python?
November 29, 2024 - We learned how to parse JSON data, access values using loops and list comprehension, handle nested arrays, and filter data based on conditions. JSON is a widely used data format, and Python provides powerful tools to work with it efficiently. By mastering these techniques, you can easily extract and manipulate data from JSON arrays in your Python projects. I hope this tutorial has helped demonstrate how to get values from a JSON array using Python.
Top answer
1 of 5
91

For reference, let's see what the original JSON would look like, with pretty formatting:

>>> print(json.dumps(my_json, indent=4))
{
    "name": "ns1:timeSeriesResponseType",
    "declaredType": "org.cuahsi.waterml.TimeSeriesResponseType",
    "scope": "javax.xml.bind.JAXBElement$GlobalScope",
    "value": {
        "queryInfo": {
            "creationTime": 1349724919000,
            "queryURL": "http://waterservices.usgs.gov/nwis/iv/",
            "criteria": {
                "locationParam": "[ALL:103232434]",
                "variableParam": "[00060, 00065]"
            },
            "note": [
                {
                    "value": "[ALL:103232434]",
                    "title": "filter:sites"
                },
                {
                    "value": "[mode=LATEST, modifiedSince=null]",
                    "title": "filter:timeRange"
                },
                {
                    "value": "sdas01",
                    "title": "server"
                }
            ]
        }
    },
    "nil": false,
    "globalScope": true,
    "typeSubstituted": false
}

That lets us see the structure of the data more clearly.

In the specific case, first we want to look at the corresponding value under the 'value' key in our parsed data. That is another dict; we can access the value of its 'queryInfo' key in the same way, and similarly the 'creationTime' from there.

To get the desired value, we simply put those accesses one after another:

my_json['value']['queryInfo']['creationTime'] # 1349724919000
2 of 5
23

I just need to know how to translate that into specific code to extract the specific value, in a hard-coded way.

If you access the API again, the new data might not match the code's expectation. You may find it useful to add some error handling. For example, use .get() to access dictionaries in the data, rather than indexing:

name = my_json.get('name') # will return None if 'name' doesn't exist

Another way is to test for a key explicitly:

if 'name' in resp_dict:
    name = resp_dict['name']
else:
    pass

However, these approaches may fail if further accesses are required. A placeholder result of None isn't a dictionary or a list, so attempts to access it that way will fail again (with TypeError). Since "Simple is better than complex" and "it's easier to ask for forgiveness than permission", the straightforward solution is to use exception handling:

try:
    creation_time = my_json['value']['queryInfo']['creationTime']
except (TypeError, KeyError):
    print("could not read the creation time!")
    # or substitute a placeholder, or raise a new exception, etc.
๐ŸŒ
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 ...
Find elsewhere
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ python-program-to-extract-a-single-value-from-json-response
Python program to extract a single value from JSON response
July 12, 2023 - The JSON objects are converted into dictionaries with the help of "json()" method. These dictionaries are then parsed to pick specific information. Here, we will extract the BPI value by accessing the nested objects. The dictionary keys refer to certain attributes and properties and their values ...
๐ŸŒ
Real Python
realpython.com โ€บ python-json
Working With JSON Data in Python โ€“ Real Python
August 20, 2025 - The Python object that you get from json.load() depends on the top-level data type of your JSON file. In this case, the JSON file contains an object at the top level, which deserializes into a dictionary. When you deserialize a JSON file as a Python object, then you can interact with it nativelyโ€”for example, by accessing the value ...
๐ŸŒ
Quora
quora.com โ€บ How-do-I-extract-nested-JSON-data-in-python
How to extract nested JSON data in python - Quora
ALGORITHM to Extract (key,val) pair in a nested JSON_OBJECT: ... I have attached link to the python script that extracts each key,value pair. Go through the README file for further details. ... Top 8 apartment amenities residents really want today. Users seek apartment buildings with the best amenities. Learn which ones are worth the investment. ... A: These days, it is ABC. Why? Well, build-in for almost all major platform and frameworks. ... Next, from the method, get 1 Object or a list of Objects.
๐ŸŒ
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: ...
๐ŸŒ
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?
# Load JSON from a string json_data ... "Alex", "age": 7 } ] } ''' data = json.loads(json_data) Define a recursive function to traverse the JSON object and extract all values associated with the specified key....
๐ŸŒ
Zyte
zyte.com โ€บ home โ€บ blog โ€บ json parsing with python [practical guide]
A Practical Guide to JSON Parsing with Python
July 6, 2023 - 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
There is a fairly direct way to do it by loading the JSON into an object's __dict__ property. ... You're really not going to need to parse JSON from within a Python program. That doesn't make much sense in practicality.
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 66420471 โ€บ how-to-get-value-from-json-format
python - How to get value from JSON format - Stack Overflow
since the returned value of a json is an object (JavaScript Object Notation) you can treat it as such and just destructure the object with the [] notation as other pointed out response_json["id"] ... I solve this using a naive way. which is convert the object to JSON > python list > python dictionary ยท response = requests.get(url, headers=headers, proxies=proxyDict) response_list = response.json() response_dict = response_list[0] print(response_dict["id"])