WeCode
Academy
Tutorials
Web Development
Bootstrap
CSS
HTML
JavaScript
jQuery
Node.js
PHP
React
TypeScript
Programming
C
C#
C++
Go
Java
Python
Rust
Data and Databases
NumPy
Pandas
SQL
Tools
Bash
Git
Projects
Project: A Tiny Shell in C
Project: Bank Account System
Project: Library Management System
Project: Portfolio Page
Project: Quiz App in React
Project: Sales Data Analysis
Project: Server Log Analyser
Project: To-Do REST API
Project: URL Shortener
Project: Word Counter in Four Languages
All tutorials ❯
Paths
References
Practice
Try it editor
Quizzes
How To recipes
Tools
Glossary
My Learning
🌙
Dark mode
Home
›
How To
›
Python
Read and write a JSON file
json.dump writes a dictionary to a file; json.load reads it back.
Example
python
import json, tempfile, os data = {'name': 'Ada', 'scores': [90, 85]} path = os.path.join(tempfile.gettempdir(), 'demo.json') with open(path, 'w') as f: json.dump(data, f) with open(path) as f: print(json.load(f))
Run ❯
Reset
Open in editor »
More Python recipes
Read a file line by line
Count words in a text
Reverse a string
Check if a number is prime
Merge two dictionaries