You don't dump a string but to a string.

d = {"foo": "bar"}
j = json.dumps(d)
print(j)

Output:

{"foo": "bar"}

It makes no sense to use a string as the argument of json.dumps which is expecting a dictionary or a list/tuple as the argument.

Serialize obj to a JSON formatted str using this conversion table.

Answer from user1907906 on Stack Overflow
🌐
Python
docs.python.org › 3 › library › json.html
json — JSON encoder and decoder
3 weeks ago - In JSON, an object refers to any data wrapped in curly braces, similar to a Python dictionary. ... Be cautious when parsing JSON data from untrusted sources. A malicious JSON string may cause the decoder to consume considerable CPU and memory resources. Limiting the size of data to be parsed is recommended. This module exposes an API familiar to users of the standard library marshal and pickle modules. ... >>> import json >>> json.dumps(['foo', {'bar': ('baz', None, 1.0, 2)}]) '["foo", {"bar": ["baz", null, 1.0, 2]}]' >>> print(json.dumps("\"foo\bar")) "\"foo\bar" >>> print(json.dumps('\u1234')) "\u1234" >>> print(json.dumps('\\')) "\\" >>> print(json.dumps({"c": 0, "b": 0, "a": 0}, sort_keys=True)) {"a": 0, "b": 0, "c": 0} >>> from io import StringIO >>> io = StringIO() >>> json.dump(['streaming API'], io) >>> io.getvalue() '["streaming API"]'
🌐
GeeksforGeeks
geeksforgeeks.org › python › json-dumps-in-python
json.dumps() in Python - GeeksforGeeks
The json.dumps() function in Python converts a Python object (such as a dictionary or list) into a JSON-formatted string.
Published   January 13, 2026
Discussions

python - Using json.dumps(string) to dump a string - Stack Overflow
You don't dump a string but to a string. ... It makes no sense to use a string as the argument of json.dumps which is expecting a dictionary or a list/tuple as the argument. More on stackoverflow.com
🌐 stackoverflow.com
Python json dump - Stack Overflow
you are right, me neither, but ... and not python 2017-03-24T14:49:22.913Z+00:00 ... I think it is a shell thing. Although I have no % in my shell prompt (using zsh), if I switch to bash this problem disappears. Thanks for the help guys. 2017-03-24T14:58:16.747Z+00:00 ... I just had the same thing happen using zsh. Adding a newline fixed it. Good to know. 2017-03-24T21:16:52.297Z+00:00 ... The reason is that print(json.dumps(data, indent=4)) ... More on stackoverflow.com
🌐 stackoverflow.com
json.dump with python.dump
How could I do this but have the language be python when it dumps? You can't. I need to do this because json does not read tuples and other things I am wanting to save into the file. So change them into lists. More on reddit.com
🌐 r/learnpython
27
1
August 1, 2023
python json dumps - Stack Overflow
The u just indicates it's a unicode string in python < 3.0. Are you sure you want to convert to simple strings? ... You don't get rid of ", you're evaluating the string and returning a list. str_w_quotes is a terrible name for a list ... seems like you are passing my_str to json.dumps otherwise ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Towards Data Science
towardsdatascience.com › home › latest › you must know python json dumps, but maybe not all aspects
You Must Know Python JSON Dumps, But Maybe Not All Aspects | Towards Data Science
January 20, 2025 - Python has built-in support to JSON documents, by its "json" module. I bet most of us have used it, and some of us have used it a lot. We know that we can use the json.dumps() method to easily convert a Python dictionary object into a JSON string.
🌐
Quora
quora.com › In-Python-what-do-json-dump-and-json-load-do
In Python, what do json.dump and json.load do? - Quora
Answer (1 of 3): json is a data transfer mechanism - originally it was design as part of the Java and Javascript environment but JSON is now widely used in many places. json defines a number of different data types : integer, float, string, and also lists and dictionaries. The nice thing about ...
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-difference-between-json-dump-and-json-dumps
Difference between json.dump() and json.dumps() - Python - GeeksforGeeks
July 3, 2025 - import json # Data to be written dictionary ={ "id": "04", "name": "sunil", "department": "HR" } # Serializing json json_object = json.dumps(dictionary, indent = 4) print(json_object)
Find elsewhere
🌐
iO Flood
ioflood.com › blog › python-json-dumps
Python json.dumps() | Step-by-Step Guide
February 1, 2024 - In this example, we first define a Python dictionary named ‘data’. We then use the json.dumps() function to convert this dictionary into a JSON string, which we store in the variable ‘json_data’. Finally, we print ‘json_data’, which ...
🌐
GeeksforGeeks
geeksforgeeks.org › python › json-dump-in-python
json.dump() in Python - GeeksforGeeks
January 13, 2026 - The json.dump() function in Python is used to convert (serialize) a Python object into JSON format and write it directly to a file.
🌐
Rayobyte
rayobyte.com › blog › how-to-use-json-dumps-in-python
How to Store Scraped Web Data in Python Using JSON Dumps
March 26, 2025 - Learning how to use json dumps as efficiently and effectively as possible paves the way for easy data storage, seamless transmission, and practical downstream analysis, optimizing the overall efficacy of your web scraping projects. In Python, the ‘json.dumps’ function is part of the standard library’s ‘json’ module.
🌐
Beautiful Soup
tedboy.github.io › python_stdlib › generated › generated › json.dumps.html
json.dumps() — Python Standard Library
Serialize obj to a JSON formatted str. If skipkeys is true then dict keys that are not basic types (str, unicode, int, long, float, bool, None) will be skipped instead of raising a TypeError. If ensure_ascii is false, all non-ASCII characters are not escaped, and the return value may be a unicode instance. See dump ...
🌐
DataCamp
datacamp.com › tutorial › json-data-python
Python JSON Data: A Guide With Examples | DataCamp
December 3, 2024 - This function is used to serialize a Python object into a JSON string. The dumps() function takes a single argument, the Python object, and returns a JSON string.
🌐
Educative
educative.io › answers › what-is-the-difference-between-jsonloads-and-jsondumps
What is the difference between json.loads() and ...
In this case, it converts the JSON string into a Python dictionary, because the JSON string represents an object with key-value pairs. In this example, a json object is passed in the json.dumps() function, and its data is extracted and returned in the form of a string:
🌐
Oreate AI
oreateai.com › blog › understanding-jsonloads-and-jsondumps-in-python-a-friendly-guide › 5e9af6929f92a705349cc4d4bfe74f75
Understanding json.loads and json.dumps in Python: A Friendly Guide - Oreate AI Blog
January 15, 2026 - It takes a Python object (like our newly created dictionary) and converts it back into a JSON-formatted string. This can be particularly useful when you're preparing data to send over an API or save to a file.
🌐
Codecademy
codecademy.com › docs › python › json module › .dump()
Python | JSON Module | .dump() | Codecademy
May 29, 2025 - The .dump() function encodes a Python object as a JSON file. The process is known as serialization. The encoding conversion is based on this table.
🌐
Anthropic
anthropic.com › engineering › advanced-tool-use
Introducing advanced tool use on the Claude Developer ...
November 24, 2025 - Instead of each tool result returning to Claude, Claude writes a Python script that orchestrates the entire workflow. The script runs in the Code Execution tool (a sandboxed environment), pausing when it needs results from your tools. When you return tool results via the API, they're processed by the script rather than consumed by the model.