Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Clear out junk files and repair common Windows errorsFree Scan →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Use Python’s built-in json module: open a text file in write mode with UTF-8 encoding, then pass the dictionary and open file handle to json.dump(). Add indent=4 for a readable file.
Save a dictionary directly to a JSON file
This example writes a Python dictionary to data.json:
import json
my_dict = {"name": "Ada", "language": "Python"}
with open("data.json", "w", encoding="utf-8") as json_file:
json.dump(my_dict, json_file, indent=4)
The with block closes the file when writing is finished. The resulting file contains valid JSON with indentation and line breaks, making it easier to inspect.
Load the JSON file back into Python
Use json.load() with an open file handle to read the saved data:
Free tools Windows power users keep installed
One-click scans. No signup required.
#1 Best Overall
import json
with open("data.json", "r", encoding="utf-8") as json_file:
loaded_dict = json.load(json_file)
For ordinary string-keyed dictionaries containing JSON-compatible values, loaded_dict will contain the data represented in the file. Python’s tutorial recommends explicitly using UTF-8 when reading and writing JSON text files: Python tutorial: Input and Output.
Choose readable, compact, or sorted output
These options affect presentation, not whether the dictionary can be written:
Rank #2
- Readable: pass
indent=4to format nested structures across multiple lines. - Compact: omit
indentfor compact output, or useseparators=(",", ":")for the most compact representation. - Sorted keys: add
sort_keys=Trueif alphabetic key ordering is useful for reviewing diffs or comparing files.
For example, readable output with sorted keys is json.dump(my_dict, json_file, indent=4, sort_keys=True).
What Python values can be saved?
The JSON encoder handles dictionaries, lists, tuples, strings, numbers, booleans, and None using the conversions documented by Python. A tuple is represented as a JSON array, and None becomes JSON null. A value outside the supported conversions raises TypeError by default; supply a default conversion function or a custom encoder if you need to represent such objects. See the Python 3.13 json module reference.
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallCrashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteNon-string dictionary keys
JSON object keys are strings. Python can convert certain non-string dictionary keys to strings during serialization, so loading the file may not recreate the original dictionary exactly. If key types matter, convert keys deliberately and account for that change when loading.
NaN and infinity
By default, Python permits NaN, Infinity, and -Infinity in its output, although these are not valid JSON numbers under the JSON specification. Use allow_nan=False if the file must reject those values rather than write them.
Quick Recap
Best Value
Common mistakes to avoid
- Passing a filename to
json.dump(): its second argument must be a writable file-like object, not a path string. Open the file first, as in the examples. - Setting encoding on
json.dump(): specifyencoding="utf-8"inopen(). Theencodingargument tojson.dump()was removed in Python 3.9. - Appending repeated dumps as if they were separate documents: JSON is not a framed protocol. Repeated calls to
dump()on the same file can produce invalid JSON; write one complete JSON document per file instead.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




