Create a Python script that:
- Reads data from JSON files
- Loops through a list of items
- Extracts nested values
- Merges multiple JSON files without overlap
This project demonstrates how to work with JSON files in Python using
the built-in json
module.
It covers:
- Reading JSON files
- Iterating through list values (e.g., skills)
- Extracting nested dictionary values (e.g., job role, years, company)
- Adding new keys to JSON data
- Merging multiple JSON files into one consolidated JSON file
project/
│── data1.json # Sample JSON file (Employee 1)
│── data2.json # Sample JSON file (Employee 2)
│── json_read_write.py # Main Python script
│── updated_data1.json # Output after modifying data1.json
│── updated_data2.json # Output after modifying data2.json
│── merged_data.json # Final merged JSON file
│── README.md # Documentation
-
Clone this repository
git clone https://github.com/your-username/json-merge-py.git cd json-merge-py
-
Make sure Python 3 is installed on your system.
-
Run the script:
python json_read_write.py
-
Check the generated files:
updated_data1.json
updated_data2.json
merged_data.json
{
"id": 101,
"name": "Imran Ahmad",
"skills": ["Python", "Selenium", "PyTest"],
"experience": {
"role": "Automation Tester",
"years": 3,
"company": "Heaven of Freedom"
}
}
{
"id": 101,
"name": "Imran Ahmad",
"skills": ["Python", "Selenium", "PyTest"],
"experience": {
"role": "Automation Tester",
"years": 3,
"company": "Heaven of Freedom"
},
"status": "processed"
}
[
{
"id": 101,
"name": "Imran Ahmad",
"skills": ["Python", "Selenium", "PyTest"],
"experience": {
"role": "Automation Tester",
"years": 3,
"company": "Heaven of Freedom"
},
"status": "processed"
},
{
"id": 102,
"name": "Nahid Anjum",
"skills": ["Java", "TestNG", "API Testing"],
"experience": {
"role": "QA Engineer",
"years": 2,
"company": "Never More"
},
"status": "rejected"
}
]
- Python 3
- JSON module
- Add support for merging all JSON files dynamically from a folder.
- Include error handling for malformed or empty JSON files.
- Extend script to handle nested merges across multiple levels.
- Add unit tests to validate JSON processing.
- Provide a command-line interface (CLI) for flexible usage.