I recommend using the awesome requests library:

import requests

url = 'http://maps.googleapis.com/maps/api/directions/json'

params = dict(
    origin='Chicago,IL',
    destination='Los+Angeles,CA',
    waypoints='Joplin,MO|Oklahoma+City,OK',
    sensor='false'
)

resp = requests.get(url=url, params=params)
data = resp.json() # Check the JSON Response Content documentation below

JSON Response Content: https://requests.readthedocs.io/en/master/user/quickstart/#json-response-content

Answer from Zach Kelling on Stack Overflow
🌐
ReqBin
reqbin.com › code › python › rituxo3j › python-requests-json-example
How do I get JSON using the Python Requests?
To request JSON data from the server using the Python Requests library, call the request.get() method and pass the target URL as a first parameter. The Python Requests Library has a built-in JSON decoder and automatically converts JSON strings ...
Discussions

python - What's the best way to parse a JSON response from the requests library? - Stack Overflow
I'm using the python requests module to send a RESTful GET to a server, for which I get a response in JSON. The JSON response is basically just a list of lists. What's the best way to coerce the More on stackoverflow.com
🌐 stackoverflow.com
python - How can I extract a single value from a nested data structure (such as from parsing JSON)? - Stack Overflow
I wrote some code to get data from a web API. I was able to parse the JSON data from the API, but the result I gets looks quite complex. Here is one example: >>> my_json {'name': 'ns1: More on stackoverflow.com
🌐 stackoverflow.com
Help With Python, API GET Requests, and JSON
So requests.get() returns a requests.models.Response object, not the raw JSON data. In order to access the raw text that you are seeing when you visit that URL in your browser, you would need to call response.text. That being said, the requests library has a built-in JSON decoder so you don't actually even need to use the json library. You can just do data = response.json() and that will yield a dict object that is JSON decoded from the response text. More on reddit.com
🌐 r/learnpython
2
2
April 26, 2018
[Python Requests] Parsing JSON with request.get

Have you ever worked with lists and dictionaries in python? They work like this:

>>> foo={ "type": "event.list", "events": [ { "event_name" : "ordered-item", "created_at": 1391691571, "user_id" : "314159" }, { "event_name" : "invited-friend", "created_at": 1389913941, "user_id" : "314159", "metadata": { "invitee_email": "pi@example.org", "invite_code": "ADDAFRIEND" } }]}
>>> foo['events']
[{'event_name': 'ordered-item', 'created_at': 1391691571, 'user_id': '314159'}, {'metadata': {'invitee_email': 'pi@example.org', 'invite_code': 'ADDAFRIEND'}, 'event_name': 'invited-friend', 'created_at': 1389913941, 'user_id': '314159'}]
>>> foo['events'][0]
{'event_name': 'ordered-item', 'created_at': 1391691571, 'user_id': '314159'}
>>> foo['events'][0]['event_name']
'ordered-item'
>>>

See the official tutorial for more info about lists and dicts.

More on reddit.com
🌐 r/learnpython
5
1
June 22, 2016
🌐
PYnative
pynative.com › home › python › json › parse a json response using python requests library
Parse a JSON response using Python requests library
May 14, 2021 - Just execute response.json(), and that’s it. response.json() returns a JSON response in Python dictionary format so we can access JSON using key-value pairs. You can get a 204 error In case the JSON decoding fails.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › API › Request › json
Request: json() method - Web APIs | MDN
November 7, 2025 - const obj = { hello: "world" }; const request = new Request("/myEndpoint", { method: "POST", body: JSON.stringify(obj), }); request.json().then((data) => { // do something with the data sent in the request });
🌐
GeeksforGeeks
geeksforgeeks.org › response-json-python-requests
response.json() - Python requests - GeeksforGeeks
April 28, 2025 - In Python’s requests library, the response.text attribute allows developers to access the content of the response returned by an HTTP request. This content is always returned as a Unicode string, making it easy to read and manipulate. Whether the response body contains HTML, JSON, XML, or plain text
🌐
datagy
datagy.io › home › python requests › response.json() – working with json in python requests
response.json() - Working with JSON in Python requests • datagy
December 30, 2022 - The requests library comes with a helpful method, .json(), that helps serialize the response of the request. In order to look at an example, let’s the public endpoints provided by the website reqres.in. These endpoints work without signing up, so following along with the tutorial is easy. Let’s see how we can access the /users endpoint and serialize the response into a Python dictionary using the .json() method: # Serializing a GET Request with .json() import requests resp = requests.get('https://reqres.in/api/users') resp_dict = resp.json() print(type(resp_dict)) # Returns: <class 'dict'>
Find elsewhere
🌐
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 ...
🌐
Python Forum
python-forum.io › thread-13001.html
GET Request and JSON response
Good morning I'm trying to use Python to connect to a MySQL Database, so I'm trying to use a GET request and a PHP script. The code I have so far is: import requests import json print 'Hello, World' url = 'https://www.thebar.inthepub.co.uk/restt...
🌐
Medium
medium.com › @themathlab › api-requests-json-parsing-in-python-a-guide-in-data-collection-31e985981ea3
API Requests & JSON Parsing in Python: A Guide in Data Collection | by The Math Lab | Medium
April 2, 2025 - The key function here is requests.get() which is used to send a request to the API. Another important thing is the status_code which is used to check the status of the request, whether it was successful or not.
🌐
Requests
requests.readthedocs.io › en › latest › user › quickstart
Quickstart — Requests 2.33.0 documentation
Requests allows you to provide these arguments as a dictionary of strings, using the params keyword argument. As an example, if you wanted to pass key1=value1 and key2=value2 to httpbin.org/get, you would use the following code:
🌐
ProxiesAPI
proxiesapi.com › articles › parsing-json-responses-from-apis-in-python-requests
Parsing JSON Responses from APIs in Python Requests | ProxiesAPI
import requests response = requests.get('https://api.example.com/data') data = response.json() print(data['key1'])
🌐
Towards Data Science
towardsdatascience.com › home › latest › json and apis with python
JSON and APIs with Python | Towards Data Science
January 28, 2025 - requests.get('https://api.covid19api.com/summary').json() As previously mentioned, we would like to make a pandas dataframe that has two columns: countries, and the number of total confirmed cases for that country. We can do so by looping through the values of the ‘Countries’ key of our outer dictionary:
🌐
ReqBin
reqbin.com › req › python › 5nqtoxbx › get-json-example
Python | How to get JSON from URL?
January 17, 2023 - To request JSON from an URL using Python, you need to send an HTTP GET request to the server and provide the Accept: application/json request header with your request. The Accept header tells the server that our Python client is expecting JSON.
🌐
Real Python
realpython.com › python-requests
Python's Requests Library (Guide) – Real Python
July 23, 2025 - To try this out, you can make a GET request to GitHub’s REST API by calling get() with the following URL: ... Congratulations! You’ve made your first request. Now you’ll dive a little deeper into the response of that request. A Response is the object that contains the results of your request. Try making that same request again, but this time store the return value in a variable so you can get a closer look at its attributes and behaviors:
🌐
Stack Abuse
stackabuse.com › how-to-get-json-from-a-url-in-python
How to Get JSON from a URL in Python
February 14, 2025 - Once we have requests installed, we can use it to fetch JSON data from a URL using the get() method.
🌐
Bright Data
brightdata.com › blog › how-tos › parse-json-data-with-python
Guide to Parsing JSON Data With Python
September 16, 2025 - Take a look at the conversion table below to see how JSON values are converted to Python data by json: Consider that you need to make an API and convert its JSON response to a Python dictionary. In the example below, we will call the following API endpoint from the {JSON} Placeholder project to get some fake JSON data: ... You can call that API with the urllib module from the Standard Library and convert the resulting JSON to a Python dictionary as follows: import urllib.request import json url = "https://jsonplaceholder.typicode.com/todos/1" with urllib.request.urlopen(url) as response: body_json = response.read() body_dict = json.loads(body_json) user_id = body_dict['userId'] # 1
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.
🌐
Medium
medium.com › @obotnt › understanding-the-difference-between-get-json-and-request-json-in-flask-d612d1fbc895
Understanding the Difference Between get_json() and request.json in Flask | by Osama Bin Obaid | Medium
September 24, 2024 - get_json(): You need to explicitly call this method to parse the JSON. It’s a more flexible approach when you need control over how the JSON is handled. request.json: This is more implicit and provides direct access to the parsed JSON without calling a method. Return Values: get_json(): Returns None if there is no JSON data (or invalid JSON, depending on the silent flag).
🌐
Reddit
reddit.com › r/learnpython › help with python, api get requests, and json
r/learnpython on Reddit: Help With Python, API GET Requests, and JSON
April 26, 2018 -

Hello, I am very new to Python and am trying to use Python to grab a JSON file from an API in order to extract data. I believe I have done the string concatenation properly, with the URL and Artist values I have created. If you visit the URL here you are able to see the JSON text correctly. However, I am trying to store this data in an object, however it does not seem to be working for some reason. Printing should yield the JSON text, but it does not.

Here is my code and the error I get when trying to run it. I'm really stumped at the moment because a lot of the tutorials I've seen seem to show these steps working fine.