Home / CodeScripts / Scripts / How to Read and Write JSON Files in Python

How to Read and Write JSON Files in Python

How to Read and Write JSON Files in Python
  • Category Scripts
  • Type Script
  • Platform Cross-platform
  • Language Python
  • Price Free
  • Copy 7 426
  • Comments 0
Go to Code
How to Read and Write JSON Files in Python

How to Read and Write JSON Files in Python

Copy this Python snippet on Clayi Code — one click, no account required. Free code examples with copy-ready formatting — built for developers who want speed without hunting forums.

What it does and when to use

A working code example you can drop into your project — automation, algorithms, file handling, or application logic. Use it as a starting point when you want boilerplate instead of writing everything from zero.

How to copy from Clayi Code

Copy the snippet, save with the right file extension, install any listed dependencies, and run with your usual toolchain.

Run it safely

Match your installed language version and packages. Check import, require, or using lines — install missing libraries first. Run in a sandbox or staging folder before executing with admin or network access.

Script reference

Category: Scripts. Language: Python. Platform: Cross-platform. Format: Script.

Popularity
0%
  • Votes: 693
  • Comments: 0

How to Read and Write JSON Files in Python

import json

# Data to be written to the JSON file
data_to_save = {
    "site_name": "SnippetShare",
    "is_active": True,
    "features": ["Copy", "Paste", "SEO"]
}

# 1. Writing data to a JSON file
with open("config.json", "w", encoding="utf-8") as file:
    json.dump(data_to_save, file, indent=4, ensure_ascii=False)

# 2. Reading data back from the JSON file
with open("config.json", "r", encoding="utf-8") as file:
    loaded_data = json.load(file)
    print(loaded_data["site_name"])
Free snippet — copy & paste!
Copy this snippet for free on Clayi Code. One click — no account required.

Similar Snippets

Populer Snippets

There are no comments yet :(

How to Read and Write JSON Files in Python
Tell us what you think about "How to Read and Write JSON Files in Python"
Information
Users of Guests are not allowed to comment this publication.