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
Answer from dm03514 on Stack Overflow
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.
🌐
Reddit
reddit.com › r/learnpython › is there a python package to tell me 'how' to access specific data inside a json file?
r/learnpython on Reddit: Is there a Python package to tell me 'how' to access specific data inside a JSON file?
December 27, 2023 -

I'm quite new to python and programming as a whole. But I have a complicated (for me!) JSON file that is an output from some software.
I am trying build a drawing from the JSON file, but I am struggling to access any of it (due to my lack of knowledge).

I have run the JSON file through 'json2tree' which is extremely useful and shows the data in tree view, but I can't work out how to 'access' this data in python code.

I was wondering if anyone knows a package such as json2tree, but instead of just displaying the data, when clicking onthe data, it might show the code that would be used to access said data?
Is there something in Python that I should focus on to understand using JSON inside of python, such as more tutorials on Lists/Dicts?

I have tried a search, but I am not sure I am using the right terms, as I cannot find anything - but perhaps it doesn't exist!

Thanks in advance!

Discussions

How to extract specific data from JSON object using python? - Stack Overflow
I'm trying to scrape a website and get items list from it using python. I parsed the html using BeaufitulSoup and made a JSON file using json.loads(data). The JSON object looks like this: { ". More on stackoverflow.com
🌐 stackoverflow.com
parsing JSON files in python to get specific values - Stack Overflow
I'm much more interested in finding a way to grab specific values within a json file, not an entire list of data. Any help is appreciated, and please point it out if there is already a thread that ACTUALLY covers this. Thank you! ... Json.loads will also decode that dictionary. So to access cpu_count for example it would be json_data["Hosts"]["cpu_count"]. The json library will turn everything into a standard python data type (dict, list, int, str) or from ... More on stackoverflow.com
🌐 stackoverflow.com
python - Get specific data from json output - Stack Overflow
To a file with data only from the summary: distance in text format? Thank You! ... Do a json.loads(response), it will be a dict, so iterate o extract your desired key. ... If you search in your browser for "JSON input output" and "Python text file", you'll find references that can explain this ... More on stackoverflow.com
🌐 stackoverflow.com
Extracting data from JSON file
Can you show an example of the data? More on reddit.com
🌐 r/learnpython
11
2
March 30, 2024
🌐
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 - The base URL is combined with the final URL, which includes both currencies, to fetch the result. An API call is then sent. The data is obtained by accessing the JSON Data's "conversion rate" key, and the resulting conversion rate is then printed.
🌐
Bright Data
brightdata.com › faqs › json › extract-json-response-python
How to Extract Data from a JSON Response in Python?
April 17, 2025 - With the JSON data parsed into a Python dictionary, you can extract specific values. For instance, if the JSON response looks like this: { "user": { "id": 123, "name": "John Doe", "email": "[email protected]" } } Here’s the complete code in ...
Find elsewhere
🌐
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 - Programming · Python · Sharath Ravi · 1 min read · ·Apr 6, 2023 · -- Listen · Share · Press enter or click to view image in full size · Photo by Hitesh Choudhary on Unsplash · import json def extract_key_value(json_data, key): """Extracts ...
🌐
Python Guides
pythonguides.com › json-data-in-python
How To Get Values From A JSON Array In Python?
April 27, 2026 - Data Validation: Consider using pydantic if you need to ensure the values you extract follow a specific schema. In this tutorial, I showed you several ways to get values from a JSON array in Python.
🌐
Reddit
reddit.com › r/learnpython › extracting data from json file
r/learnpython on Reddit: Extracting data from JSON file
March 30, 2024 -

I have a large JSON file with multiple JSON objects. Each object should contain data that includes "sounds" and "pos". That is, for each object, there is a section called "sounds" which contains things like IPA and accent tags, and a section called "pos" which contains parts of speech. I am trying to extract the "sounds" and "pos" sections for each object from the file. I am very new to python, so I am unsure of what I'm doing wrong. When I run the below code, it prints "None" many times.

import json

def extract_specific_data_from_entries(json_file, keys):
 extracted_data_list = []
 with open(json_file, 'r', encoding='utf-8') as file:
   for line in file: data = json.loads(line.strip())
   extracted_data = extract_specific_data(data, keys) 

extracted_data_list.append(extracted_data) return extracted_data_list

def extract_specific_data(data, keys):
 extracted_data = data
 for key in keys:
   if isinstance(extracted_data, dict):
     extracted_data = extracted_data.get(key) 
     elif isinstance(extracted_data, list):
       try: 
         key = int(key)
         extracted_data = extracted_data[key]
       except (ValueError, IndexError):
         extracted_data = None
     else:
       extracted_data = None 
       break 
return extracted_data

if name == "main":
 json_file = "kaikki.org-dictionary-English.json"
  keys = ["sounds", "pos"]  
  extracted_data_list = extract_specific_data_from_entries(json_file, keys) 

print(extracted_data_list)

🌐
Zyte
zyte.com › home › blog › json parsing with python [practical guide]
JSON Parsing with Python [Practical Guide]
December 3, 2024 - When traversing JSON data in Python, depending on the complexity of the object, there are more advanced libraries to help you get to the data with less code. JMESPath is a query language designed to work with JSON data. It allows you to extract ...
🌐
YouTube
youtube.com › automate with rakesh
Python JSON Parsing: A Step-by-Step Guide to Extract Data from JSON - YouTube
In this comprehensive tutorial, learn the ins and outs of Python JSON parsing. Dive into the world of data manipulation as we explore the essential technique...
Published: August 20, 2023
Views: 19K
🌐
Oxylabs
oxylabs.io › blog › python-parse-json
Reading & Parsing JSON Data With Python: Tutorial
To put it simply, extracting data ... the data in a dictionary or list. You can then access specific values using dictionary keys or list indices....
🌐
Linux Hint
linuxhint.com › search_json_python
How to search for data in JSON using python – Linux Hint
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 ...
🌐
YouTube
youtube.com › max goodridge
Extracting Data from a JSON Response in Python (Python for Beginners) | Part 34 - YouTube
Enjoyed my video? Leave a like! GitHub Link: https://github.com/maxg203/Python-for-Beginners Personal Website: http://maxgoodridge.com
Published: October 29, 2016
Views: 85K
🌐
TutorialsPoint
tutorialspoint.com › article › python-program-to-extract-a-single-value-from-json-response
Python program to extract a single value from JSON response
July 12, 2023 - Since we are using Python, we will convert these objects into dictionaries to retrieve values from the response. In this approach, we will use an API endpoint to retrieve data from the server and extract specific values from the JSON response ? import requests print("Welcome to the live bitcoin Price index") json_data = requests.get('https://api.coindesk.com/v1/bpi/currentprice.json').json() # Extract disclaimer disclaimer = json_data["disclaimer"] print(disclaimer) # Extract BPI value bpi = json_data["bpi"]["USD"]["rate"] print(f"The real time BPI value for the United states of America is: {bpi}") # Extract time time = json_data["time"]["updated"] print(f"The index was viewed at Universal time: {time}")
🌐
Stack Overflow
stackoverflow.com › questions › 70943324 › how-to-get-specific-data-from-json-file-using-python
how to get specific data from json file using python - Stack Overflow
this is my code below from pybit import HTTP import json session = HTTP("https://api.bybit.com",api_key=xxxx, api_secret=xxxx) g=session.get_wallet_balance(coin="USD...