json.dumps() converts a dictionary to str object, not a json(dict) object! So you have to load your str into a dict to use it by using json.loads() method

See json.dumps() as a save method and json.loads() as a retrieve method.

This is the code sample which might help you understand it more:

import json

r = {'is_claimed': 'True', 'rating': 3.5}
r = json.dumps(r)
loaded_r = json.loads(r)
loaded_r['rating'] #Output 3.5
type(r) #Output str
type(loaded_r) #Output dict
Answer from Iman Mirzadeh on Stack Overflow
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ how-to-convert-python-dictionary-to-json
How To Convert Python Dictionary To JSON? - GeeksforGeeks
July 12, 2025 - json.dumps(d, indent=4) converts the dictionary to a JSON-formatted string with 4-space indentation for readability.
Discussions

How to append an dictionary into a json file?
Your problem is not appending strings/jsons to a file. Your problem is later on reading it. json files usually hold ONE json object, not many concatenated objects. You can create a list, and have you dictionaries be items in that list, and then append to it, and dump the entire list as JSON to have multiple dictionaries stored, but eventually its one JSON object. If you want to modify/append a json object in a file, you read it first, load/loads, change it however you want, and write it back. # load it with open("index.json" , "r") as json_file: file_data = json.loads(json_file.read()) # change it file_data.append(dict) # write it all back with open("index.json" , "w") as json_file: json_file.write(json.dumps(file_data)) (Obviously above code assumes you already have a list dumped as a json object in index.json) More on reddit.com
๐ŸŒ r/learnpython
2
1
September 2, 2023
Python create dictionary from json values - Stack Overflow
The date is in unix time stamp and the total is an amount. What I want to do is create a dictionary from the values in date and time and not the names. More on stackoverflow.com
๐ŸŒ stackoverflow.com
Convert JSON array to Dictionary
Hmm minda sharing an anonymized version of the file? It is hard to follow. from what i read it seems like it is a list of dictionaries and you want to merge all the dictionaries right? So from functools import reduce j = json.load(...) combined = reduce(lambda x,y: {**x, **y}, j) Explanation: Reduce takes running pairs and runs the lambda which combines dictionaries. So essentially it takes a running sum of the dictionaries to combine them. Most people like looping, but this is readable to me. For loop: ... combined = j[0] for d in j[1:]: combined = {**combined, **d} Note: in py3.9+ you can do x|y instead of {**x,**y} More on reddit.com
๐ŸŒ r/learnpython
6
2
March 22, 2022
Can I create a TypedDict from a JSON dict?
At work we use mypy , which is a static type checker for Python which you can use to make Python more TypeScripty - perhaps try this with your project and see if it works for you? More on reddit.com
๐ŸŒ r/learnpython
2
2
October 5, 2021
๐ŸŒ
KDnuggets
kdnuggets.com โ€บ convert-python-dict-to-json-a-tutorial-for-beginners
Convert Python Dict to JSON: A Tutorial for Beginners - KDnuggets
To convert a Python dictionary to JSON string, you can use the dumps() function from the json module. The dumps() function takes in a Python object and returns the JSON string representation.
๐ŸŒ
Python Examples
pythonexamples.org โ€บ python-dict-to-json
Python Dictionary to JSON
In the following program, we will take an empty dictionary, and convert it into JSON string. import json myDict = {} jsonStr = json.dumps(myDict) print(jsonStr) ... In this Python JSON Tutorial, we learned how to convert Dictionary to JSON string in Python.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ convert-json-to-dictionary-in-python
Convert JSON to dictionary in Python - GeeksforGeeks
July 12, 2025 - In the below code, firstly we open the "data.json" file using file handling in Python and then convert the file to Python object using the json.load() method we have also print the type of data after conversion and print the dictionary.
๐ŸŒ
Squash
squash.io โ€บ how-to-convert-dictionary-to-json-in-python
How To Convert a Dictionary To JSON In Python - Squash Labs
Here are two possible ways to convert a dictionary to JSON in Python: The json.dumps() method is used to convert a Python object into a JSON formatted string. It takes the Python object as input and returns a JSON string representation of the ...
Find elsewhere
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ article โ€บ how-to-print-python-dictionary-into-json-format
How to print Python dictionary into JSON format?
March 24, 2026 - # Creating a dictionary with product ... 'XUT', 'Units': 120, 'Available': 'Yes'} Product: Mobile Units: 120 ยท The json.dumps() function converts a Python dictionary to a JSON-formatted string โˆ’...
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_json.asp
Python JSON
If you have a JSON string, you can parse it by using the json.loads() method. The result will be a Python dictionary.
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ convert dictionary to json python
Convert Dictionary to JSON Python - Scaler Topics
April 21, 2024 - To convert dict to JSON python, we can use the dumps() function itself. Here, we have used indent=3, which refers to the space at the beginning of the code line: ... Explanation: As seen above, we have started by importing the inbuilt JSON module from the python library.
๐ŸŒ
Python Examples
pythonexamples.org โ€บ python-create-json
Python Create JSON
json.dumps() with indent argument returns a JSON formatted string value created from the dictionary.
๐ŸŒ
Code Beautify
codebeautify.org โ€บ blog โ€บ convert-python-dictionary-to-json
Convert Python Dictionary to Json
January 20, 2023 - Using the JSON module, you can convert a Python dictionary to a JSON object. The json.dumps() function converts a Python dictionary to a JSON string, while json.dump() writes the JSON string to a file-like object.
๐ŸŒ
FavTutor
favtutor.com โ€บ blogs โ€บ dict-to-json-python
5 Ways to Convert Dictionary to JSON in Python | FavTutor
October 5, 2021 - Learn how to convert dict to json in python along with a brief introduction about dictionary and json in python.
๐ŸŒ
iO Flood
ioflood.com โ€บ blog โ€บ python-dict-to-json
Convert a Python Dict to JSON | json.dumps() User Guide
January 30, 2024 - This time, json.dumps() successfully converts the dictionary, including the list, to JSON. Remember, understanding the data types that are not JSON serializable and pre-processing your data accordingly can save you from many headaches down the line. Before we dive deeper into the conversion process, itโ€™s essential to understand the key players: Python dictionaries and JSON objects.
๐ŸŒ
Spark By {Examples}
sparkbyexamples.com โ€บ home โ€บ python โ€บ convert python dictionary to json
Convert Python Dictionary to JSON - Spark By {Examples}
May 31, 2024 - How to convert a dictionary to JSON in Python? We can use the json.dump() method and json.dumps() method to convert a dictionary to a JSON
๐ŸŒ
Analytics Vidhya
analyticsvidhya.com โ€บ home โ€บ how to convert python dictionary to json?
How To Convert Python Dictionary To JSON? - Analytics Vidhya
January 11, 2024 - Convert Python dictionaries to JSON for seamless data interchange. Use json module, methods, examples, and best practices and more.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ how to append an dictionary into a json file?
r/learnpython on Reddit: How to append an dictionary into a json file?
September 2, 2023 -

Hello I currently learning json in python i want to append a dictionary in a json file ontop of existing ones but every time i do this i get this error in VS-Code:

End of file expected.

Can somebody help me?

Here is the Code:

dict = {
    "data1" : data3,
       
    "data2" : data4        
}
    
data = json.dumps(dict)
with open("index.json" , "a") as file:
    
    json.dump(data , file)

๐ŸŒ
Board Infinity
boardinfinity.com โ€บ blog โ€บ dict-to-json-in-python
Dictionary to JSON: Conversion in Python | Board Infinity
June 16, 2026 - Learn to convert Python dictionaries to JSON strings without much effort, with the help of `json.dumps()`, and see examples in action.