Published on

How to Read and Write json data with Python


This is a short tutorial on how to use python to write and read files.


To write the following json data:

{"name": "ruan"}

To a file named /tmp/data.json, we will be using this code:

import json

data = {"name": "ruan"}
with open('data.json', 'w') as f:

When we execute that code, we will find the data inside that file:

$ cat /tmp/data.json
{"name": "ruan"}

And if we want to use python to read the data:

import json

with open('data.json', 'r') as f:

When we execute that code, we will see:

{'name': 'ruan'}

Thank You

Thanks for reading, if you like my content, feel free to check out my website, and subscrube to my newsletter or follow me at @ruanbekker on Twitter.

Buy Me A Coffee