import json
with open('result.json', 'w') as fp:
    json.dump(sample, fp)

This is an easier way to do it.

In the second line of code the file result.json gets created and opened as the variable fp.

In the third line your dict sample gets written into the result.json!

Answer from moobi on Stack Overflow
🌐
KDnuggets
kdnuggets.com › convert-python-dict-to-json-a-tutorial-for-beginners
Convert Python Dict to JSON: A Tutorial for Beginners - KDnuggets
So each book record is in a Python dictionary with the following keys: title, author, publication_year, and genre. When calling json.dumps(), we set the optional indent parameter—the indentation in the JSON string as it helps improve readability (yes, pretty printing json we are ??):
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 - Converting dictionary to JSON - Stack Overflow
The JSON is loaded into a new variable not because it is new information, but to show that the values in the new dictionary, i.e. after the JSON encode and decode round-trip, are identical. 2019-03-22T10:12:06.877Z+00:00 ... you can dump as json file too, like this with open('r.json', 'w') ... More on stackoverflow.com
🌐 stackoverflow.com
convert list of dictionary to list of json objects
Json.dumps will convert the dictionary to a string but the string is valid JSON. You see the single quotes since Python is indicating this is a string (and double quotes is being used internally). More on reddit.com
🌐 r/learnpython
7
2
October 13, 2022
JSON Effectively is a Dictionary? Change My Mind
It’s essentially a mix of dictionaries and lists. A JSON object is similar to a dictionary, and a JSON array is similar to a list. Pretty much any JSON data structure can be translated into a complex Python data object. More on reddit.com
🌐 r/learnpython
7
0
December 17, 2022
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-convert-python-dictionary-to-json
How To Convert Python Dictionary To JSON? - GeeksforGeeks
July 12, 2025 - Note: For more information, refer to Read, Write, and Parse JSON using Python ... json.dump() writes a dictionary directly into a file in JSON format. It avoids the need to manually open and write the JSON string to a file.
🌐
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.
🌐
W3Schools
w3schools.com › python › python_json.asp
Python JSON
Python has a built-in package called json, which can be used to work with JSON data. ... If you have a JSON string, you can parse it by using the json.loads() method. The result will be a Python dictionary.
🌐
Oregon State University
blogs.oregonstate.edu › logicbot › 2022 › 04 › 08 › saving-a-dictionary-with-json
Saving a dictionary with JSON – Logic_bot
I have to say that I am a little ... with it. Useless. That’s where this little one liner comes in. json.loads() turns JSON formatted data back into a dictionary that you can reference normally....
Find elsewhere
🌐
Python
docs.python.org › 3 › library › json.html
JSON encoder and decoder — Python 3.14.4 documentation
February 23, 2026 - Serialize obj to a JSON formatted str using this conversion table. The arguments have the same meaning as in dump(). ... Keys in key/value pairs of JSON are always of the type str. When a dictionary is converted into JSON, all the keys of the dictionary are coerced to strings...
🌐
Scaler
scaler.com › home › topics › convert dictionary to json python
Convert Dictionary to JSON Python - Scaler Topics
April 21, 2024 - In the below article, we shall be understanding how we can make use of json.dumps() function by utilizing its various parameters to convert the dict to json python.
🌐
Medium
medium.com › @techclaw › python-dict-to-json-simplifying-data-serialization-81a8d4eeb512
Python Dict to JSON: Simplifying Data Serialization | by TechClaw | Medium
October 12, 2023 - Converting Python dictionaries to JSON becomes necessary when you need to: Communicate with web services that require data in JSON format. Save data to a file for later use.
🌐
Python Examples
pythonexamples.org › python-dict-to-json
Python Dictionary to JSON
Python Convert Dictionary to JSON - To convert a Dict to JSON in Python, you can use json.dumps() function. json.dumps() function converts the Dictionary object into JSON string.
🌐
Replit
replit.com › home › discover › how to convert a dict to json in python
How to convert a dict to JSON in Python | Replit
March 3, 2026 - Set ensure_ascii=False in json.dumps() to stop Python from escaping non-ASCII characters into sequences like \u00e9. Specify encoding='utf-8' when opening the file to ensure it can correctly write those characters. Moving beyond the technical details and error fixes, you'll find dictionary-to-JSON ...
🌐
Code Beautify
codebeautify.org › blog › convert-python-dictionary-to-json
Convert Python Dictionary to Json
January 20, 2023 - The json.dump() function writes the contents of a Python dictionary to a file-like object in JSON format.
🌐
Reddit
reddit.com › r/learnpython › convert list of dictionary to list of json objects
r/learnpython on Reddit: convert list of dictionary to list of json objects
October 13, 2022 - Json.dumps will convert the dictionary to a string but the string is valid JSON. You see the single quotes since Python is indicating this is a string (and double quotes is being used internally).
🌐
Spark By {Examples}
sparkbyexamples.com › home › python › convert python dictionary to json
Convert Python Dictionary to JSON - Spark By {Examples}
May 31, 2024 - We can use the json.dump() method and json.dumps() method to convert a dictionary to a JSON string. ... JSON stands for JavaScript Object Notation and is used to store and transfer data in the form of text.
🌐
Linux Hint
linuxhint.com › convert_dictionary_json_python
How to convert the dictionary to JSON in python – Linux Hint
The first argument takes the dictionary object that is defined before. The second argument takes the file handler variable that is also defined before to create a JSON file. The third argument defines the indentation value. The content of the newly written JSON will be printed later as output.
🌐
Reddit
reddit.com › r/learnpython › convert json list to dictionary
r/learnpython on Reddit: convert JSON list to dictionary
January 13, 2024 -

I must first preface this with the fact that I’m extremely new to python. Like just started learning it a little over a week ago.
I have been racking my brain over how to convert a json object I opened and loaded into a dictionary from a list so I can use the get() function nested within a for loop to do a student ID comparison from another json file (key name in that file is just ID).
Below is the command I’m trying to load the json file:
With open(‘file.json’) as x: object=json.load(x)
When I print(type(object)), it shows up as class list.
Here’s a sample of what the json looks like:
[

{

“Name”: “Steel”,

“StudentID”: 3458274

“Tuition”: 24.99

},

{

“Name”: “Joe”,

“StudentID”: 5927592

“Tuition”: 14.99

}

]
HELP! Thank you!