Since you're using requests, you should use the response's json method.

import requests

response = requests.get(...)
data = response.json()

It autodetects which decoder to use.

Answer from pswaminathan on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › response-json-python-requests
response.json() - Python requests - GeeksforGeeks
July 12, 2025 - In the below code, firstly we imported the requests module and then fetch the data from an API using requests.get() method and store in variable 'response'. When we print the response it prints '<Response [200]>' which is the HTTP code that indicates success. To print the JSON data fetched we have used json() method which prints the JSON data in the Python dictionary format as seen in the output.
Discussions

Format of a JSON response with Python - Stack Overflow
I've been working on a side-project and I've been struggling with extracting data from a JSON response using Python. Whatever I come up with, I can't seem to have a proper formatted JSON result (pr... More on stackoverflow.com
🌐 stackoverflow.com
json - Python API response - How to format/choose layout of reponse - Stack Overflow
I'm about 2 days into Python (2.7 I think) and I'm trying to make the API response here a lot more readable, at the moment it's hard to decipher the English response. import json, requests respon... More on stackoverflow.com
🌐 stackoverflow.com
Converting Response to JSON?
You don't want to convert it to json format; that would give you a string for storing the data (or sending over the wire). The message is telling you that you are indexing a list as if it was a dict. You know that data is a list so "data['value']" won't work but "data[i]" might... but you don't really need to use the indexes given by range, you want the contents of the list. Only use range when you want to do arithmetic with the indexes. I am guessing this will work as well and be a bit simpler. for val in data: for item in val['value_i_want']: print(item) More on reddit.com
🌐 r/learnpython
7
3
October 18, 2020
How to Parse JSON Response in Python? - TestMu AI Community
What’s the Best Way to Parse a JSON Response from the Requests Library in Python? I’m using the Python requests module to send a RESTful GET request to a server, which returns a response in JSON format. The JSON response is essentially a list of lists. What’s the best way to convert the ... More on community.testmuai.com
🌐 community.testmuai.com
0
November 4, 2024
🌐
ReqBin
reqbin.com › req › python › 4gvqbdi1 › json-response-format-example
Python | What is the correct JSON Response Format?
December 23, 2022 - In this JSON Response Format example, we send a request to the ReqBin echo URL to get JSON Response from the server. Click Send to execute the JSON Response Format example online and see the results. The Python code was automatically generated for the JSON Response Format example.
🌐
Real Python
realpython.com › python-json
Working With JSON Data in Python – Real Python
August 20, 2025 - JSON in Python is handled using the standard-library json module, which allows for data interchange between JSON and Python data types. JSON is a good data format to use with Python as it’s human-readable and straightforward to serialize and deserialize, which makes it ideal for use in APIs and data storage.
🌐
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 - In this tutorial, you’ll learn how to parse a Python requests response as JSON and convert it to a Python dictionary. Whenever the requests library is used to make a request, a Response object is returned. The Python requests library provides a helpful method, json(), to convert a Response ...
Find elsewhere
🌐
ReqBin
reqbin.com › code › python › rituxo3j › python-requests-json-example
How do I get JSON using the Python Requests?
Python clients must explicitly notify servers that they expect JSON data by sending Accept: application/json request header. Without the Accept header, the server may send data in a different format.
🌐
Reddit
reddit.com › r/learnpython › converting response to json?
r/learnpython on Reddit: Converting Response to JSON?
October 18, 2020 -

Hi all, im trying to grab some data from a website using the requests module in Python. Here is what I have:

import requests, json

apiEndpoint = 'website.com'

r = requests.post(url = apiEndpoint)

data = r.json()

When I do a print(type(r)) I get <class 'requests.models.Response'>

When I do a print(type(data)) I get <class 'list'>

When I want to iterate through the values of data, I am getting an error.

for i in range(len(data['value'])):

for item in data['value'][i]['value_i_want']:
do something
The error I am receiving is:

"TypeError: list indices must be integers or slices, not str"

So it converted the response into a list, when I want it to convert into JSON so I can access the data easily. Any ideas?

🌐
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 - We will parse JSON response into Python Dictionary so you can access JSON data using key-value pairs. Also, you can prettyPrint JSON in the readable format.
🌐
TestMu AI Community
community.testmuai.com › ask a question
How to Parse JSON Response in Python? - TestMu AI Community
November 4, 2024 - What’s the Best Way to Parse a JSON Response from the Requests Library in Python? I’m using the Python requests module to send a RESTful GET request to a server, which returns a response in JSON format. The JSON respons…
🌐
DigitalOcean
digitalocean.com › community › tutorials › python-pretty-print-json
How to Pretty Print JSON in Python | DigitalOcean
September 16, 2025 - With Python’s json.dumps() and pprint modules, you can quickly format output for better clarity. You can also use advanced parameters to handle non-ASCII characters, serialize custom Python objects, and fine-tune whitespace for compact output. This extends beyond simple output, proving valuable for debugging API responses...
🌐
OpenAI Developer Community
community.openai.com › api
How to get API response in JSON format - API - OpenAI Developer Community
January 29, 2024 - I am calling the Assistant API using Python SDK and all response are in some custom object serialization. So far, I have been extracting the values using regex but I realized this might cause issue in the long run. Example of the response: SyncCursorPage[ThreadMessage](data=[ThreadMessage(...
🌐
ProxiesAPI
proxiesapi.com › articles › sending-and-receiving-json-data-with-python-requests
Sending and Receiving JSON Data with Python Requests | ProxiesAPI
Requests will automatically decode the JSON response so you can access it as a Python dict or list: ... response = requests.get('https://api.example.com/users/123') user = response.json() print(user['name']) # John Doe
🌐
Schulich School of Engineering
schulich.libguides.com › c.php
Parsing JSON Responses in Python - Getting Started With APIs - SSE Tech Support at Schulich School of Engineering - University of Calgary
July 30, 2024 - This module allows us to parse JSON-formatted strings into Python data structures (such as dictionaries and lists) and vice versa. The following example demonstrates what an unparsed JSON response looks like, which will hopefully get you to appreciate the importance of parsing for readability purposes.
🌐
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 raw JSON response isn't well structured so it is hard to manipulate and access data in this format. Therefore it is clear that we need to convert JSON string into a usable data structure for easier manipulation and access within the program. This process is called JSON parsing. In Python, we ...
🌐
Red Hat
docs.redhat.com › en › documentation › red_hat_satellite › 6.2 › html › api_guide › sect-api_guide-understanding_the_json_response_format
2.2. Understanding the JSON Response Format | API Guide | Red Hat Satellite | 6.2 | Red Hat Documentation
Below is an example of the format for a single-object JSON response when using the API route GET /api/domains/23 or GET /api/domains/qa.lab.example.com. curl -X GET -k -u admin:password https://satellite6.example.com/api/domains/23 | python -m json.tool { "id": 23, "name": "qa.lab.example.com", "fullname": "QA", "dns_id": 10, "created_at": "2013-08-13T09:02:31Z", "updated_at": "2013-08-13T09:02:31Z" }
🌐
Reddit
reddit.com › r/learnpython › formatting json output in python
r/learnpython on Reddit: formatting json output in Python
May 12, 2022 -

Hi,

I would like to read json into Python code, and then output processed json. In order to get started with this, I have written very basic Python, and am attempting to read in very basic json I found online.

The input json is:

{
    "firstName": "John",
    "lastName": "Doe",
    "hobbies": ["biking", "coding", "rapping"],
    "age": 35,
    "children": [
        {
            "firstName": "hector",
            "age": 6
        },
        {
            "firstName": "cassandra",
            "age": 8
        }
    ]
}

The code is:

import json

if __name__ == '__main__':
    
    print( "start" )

    # read and load input json
    json_input_filename = "input.json"
    json_input = open( json_input_filename )

    json_input_dict = json.load( json_input )

    # write output json
    json_output_filename = "output.json"
    with open( json_output_filename, 'w' ) as json_output:
        json.dump( json_string, json_output )
  

    print( f"end" )

and the output is:

"{\"firstName\": \"John\", \"lastName\": \"Doe\", \"hobbies\": [\"biking\", \"coding\", \"rapping\"], \"age\": 35, \"children\": [{\"firstName\": \"hector\", \"age\": 6}, {\"firstName\": \"cassandra\", \"age\": 8}]}"

What can I do in order to preserve something resembling the original formatting? I'm going to load this output into some other code in order to process it further.

Thank you very much