Your data is already a JSON-formatted string. You can pass it directly to requests.put instead of converting it with json.dumps again.

Change:

response = requests.put(url, data=json.dumps(data), headers=headers)

to:

response = requests.put(url, data=data, headers=headers)

Alternatively, your data can store a data structure instead, so that json.dumps can convert it to JSON.

Change:

data = '[{"$key": 8},{"$key": 7}]'

to:

data = [{"$key": 8},{"$key": 7}]
Answer from blhsing on Stack Overflow
๐ŸŒ
ReqBin
reqbin.com โ€บ code โ€บ python โ€บ m2g4va4a โ€บ python-requests-post-json-example
How do I post JSON using the Python Requests Library?
To post a JSON to the server using Python Requests Library, call the requests.post() method and pass the target URL as the first parameter and the JSON data with the json= parameter.
Discussions

How can I POST JSON data with Python's Requests library? - Stack Overflow
I need to POST JSON content from a client to a server. I'm using Python 2.7.1 and simplejson. The client is using Requests. The server is CherryPy. I can GET hard-coded JSON content from the server... More on stackoverflow.com
๐ŸŒ stackoverflow.com
APIs: Params= vs json= whats the difference?
Maybe it's a good idea to study the basics of HTTP methods: https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods A GET request has no body, so the only (practical) way of delivering data with it is through its url, so GET hostname/api/some_object/?name='test' The requestst library supports that via its params= parameter. So in this case you would do params={'name': 'test'}. Then methods like PUT and POST are meant to deliver data through their body, for which you would normally use the data= parameter. However to simplify delivering a Python structure (dict/list or some combination thereof) as a JSON encoded body, it supports that via its json= parameter. It then also sets the correct content-type header. More on reddit.com
๐ŸŒ r/learnpython
4
2
November 26, 2021
Put request using python
What response do you get by the server? Is it a 200? More on reddit.com
๐ŸŒ r/learnpython
8
1
February 8, 2022
Working with API, JSON in Python
Requests has json in its module, you shouldn't need import json. At least mine doesn't have import json when I use r.json() in my script last night. Does print() actually print json content? Json you get the value by calling the name like this, also imagine "example" is the value from r.json() if you did example = r.json() example = { "data" : { "nestkey" : "nestval" }, "datatwo" : twoval" } If I want "nestval" I do example["data"]["nestkey"] If i want "twoval" I do example["datatwo"] Obviously you dont want to end up with example[][][][][] When its deep nested. So, you just iterate through json content. This stack overflow has a couple examples to go through unknown json length, to look for a "key" https://stackoverflow.com/questions/42750220/python-iterate-json-file-where-the-json-structure-and-key-values-are-unknown So to filter by state just look through the json to find key that filters by state, and get the value. Hope this helps! More on reddit.com
๐ŸŒ r/learnpython
4
1
December 9, 2020
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ response-json-python-requests
response.json() - Python requests - GeeksforGeeks
July 12, 2025 - 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. In this way, we can pas parse JSON responses in Python. ... # import requests module import requests # Making a get request response = requests.get('https://api.github.com///') # print response print(response) # print json content print(response.json())
๐ŸŒ
Requests
requests.readthedocs.io โ€บ en โ€บ latest โ€บ user โ€บ quickstart
Quickstart โ€” Requests 2.33.0 documentation
>>> bad_r = requests.get('https://httpbin.org/status/404') >>> bad_r.status_code 404 >>> bad_r.raise_for_status() Traceback (most recent call last): File "requests/models.py", line 832, in raise_for_status raise http_error requests.exceptions.HTTPError: 404 Client Error ยท But, since our status_code for r was 200, when we call raise_for_status() we get: ... All is well. We can view the serverโ€™s response headers using a Python dictionary: >>> r.headers { 'content-encoding': 'gzip', 'transfer-encoding': 'chunked', 'connection': 'close', 'server': 'nginx/1.0.4', 'x-runtime': '148ms', 'etag': '"e1ca502697e5c9317743dc078f67693f"', 'content-type': 'application/json' }
๐ŸŒ
Apify
blog.apify.com โ€บ python-post-request
How to post JSON data with Python Requests
December 7, 2025 - The Python Requests library is widely used for making HTTP requests. Here are some tips for making effective POST requests: Sending JSON data: The best way to send JSON data is to use the json parameter of the requests.post() function.
๐ŸŒ
Apidog
apidog.com โ€บ blog โ€บ python-put-request
How to make a PUT Request in Python (2026 Guide)
February 2, 2026 - Data: The data you want to send in the PUT request. You can use the json parameter to send JSON data or the data parameter to send form-encoded data.
Find elsewhere
๐ŸŒ
ProxiesAPI
proxiesapi.com โ€บ articles โ€บ sending-and-receiving-json-data-with-python-requests
Sending and Receiving JSON Data with Python Requests | ProxiesAPI
The Python Requests library makes it easy to send HTTP requests and receive responses. When working with APIs or web services, data is often exchanged in JSON format. The Requests module has built-in support for encoding and decoding JSON seamlessly. To send JSON data in a POST or PUT request, simply pass a Python dict to the
๐ŸŒ
DEV Community
dev.to โ€บ apilover โ€บ python-requests-mastering-json-data-post-leh
Python Requests: Mastering JSON Data POST - DEV Community
February 12, 2025 - In the Body section, select JSON from the dropdown menu and enter the JSON data you want to send in the request body. Step 4: Click on the Send button to send the request and check the response.
๐ŸŒ
Apidog
apidog.com โ€บ blog โ€บ python-requests-post-json
Python Requests: How to POST JSON Data with Ease in 2026
February 4, 2026 - The requests.post() method is used to send the request, and the response status code and content are printed to the console. You can install the requests library using the following command: ... In this blog post, weโ€™ll be focusing on how ...
๐ŸŒ
Codecademy
codecademy.com โ€บ docs โ€บ python โ€บ requests module โ€บ .put()
Python | Requests Module | .put() | Codecademy
May 15, 2024 - These parameters allow a user to communicate additional information to the web server, such as data or JSON to send in the request body in order to create or update a resource. ... The response object returned by the .put() method contains various ...
๐ŸŒ
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 ...
๐ŸŒ
Stack Abuse
stackabuse.com โ€บ how-to-post-json-data-using-requests-library-in-python
How to POST JSON Data Using requests Library in Python
June 27, 2023 - Now, we can jump into the meat ... JSON data in the body of the request. We first need to import the requests library, specify the URL that we want to send the request to and define the JSON data in the data variable....
๐ŸŒ
PYnative
pynative.com โ€บ home โ€บ python โ€บ json โ€บ python post json using requests library
Python Post JSON using requests library
May 14, 2021 - Select POST request and enter your service POST operation URL. Click on Headers. In the key column enter Content-Type and in the Value column enter application/json. Click on the body section and click the raw radio button. enter your JSON data.
๐ŸŒ
W3docs
w3docs.com โ€บ python
How to POST JSON data with Python Requests?
Note: The example above is a simple test case, you can also pass your json object directly to the data parameter, like this: response = requests.post('https://httpbin.org/post', json=data)
๐ŸŒ
Real Python
realpython.com โ€บ python-requests
Python's Requests Library (Guide) โ€“ Real Python
July 23, 2025 - To add headers to requests, pass a dictionary of headers to the headers parameter in your request. To send POST data, use the data parameter for form-encoded data or the json parameter for JSON data.
๐ŸŒ
Tutorialspoint
tutorialspoint.com โ€บ python โ€บ python_requests_put_method.htm
Python Requests put() Method
Following is the basic example ... 'key2': 'value2'} # Send the PUT request with the data response = requests.put(url, json=data) # Print the response status code print('Status Code:', response.status_code) # Print ...
๐ŸŒ
Codemia
codemia.io โ€บ knowledge-hub โ€บ path โ€บ how_to_post_json_data_with_python_requests
How to POST JSON data with Python Requests?
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises
๐ŸŒ
Delft Stack
delftstack.com โ€บ home โ€บ howto โ€บ python โ€บ post json data with requests python
How to POST JSON Data With requests in Python | Delft Stack
March 4, 2025 - The simplest way to post JSON data using the requests library is by using the json parameter in the post method. This method automatically serializes your Python dictionary into a JSON string, making it effortless to send data to the server.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ apis: params= vs json= whats the difference?
r/learnpython on Reddit: APIs: Params= vs json= whats the difference?
November 26, 2021 -

Been learning more about accessing APIs and stuff. I keep running into things about params and json to do requests. I don't exactly understand what the difference between these two is. I use the same dictionaries but the keyword differs.

I tried to read the documentation but its a bit more technical than my ability.