Create a Python script that reads data from a JSON file, manipulates it, and writes the updated data back to a new JSON file.
- Working with JSON using Python's json module
- Parsing nested structures
- Reading & writing files
import json
Read JSON file
with open("data.json", "r") as f:
data = json.load(f)
print("Original Data:")
print(data)
Modify data (example: add a new key)
data["status"] = "processed"
Write to a new JSON file
with open("updated_data.json", "w") as f:
json.dump(data, f, indent=4)
print("\nUpdated JSON saved!")
- Loads data.json
- Adds or updates values in the dictionary
- Writes the updated data to updated_data.json
β Loop through a list of items
β Extract nested values
β Merge multiple JSON files
β Handling API responses
β Config file updates
β User data storage