A Python application that combines room and student data from JSON files and exports the results in JSON or XML format. Built following SOLID principles with a clean, extensible architecture.
- Data Loading: Loads student and room data from JSON files
- Data Combination: Combines rooms with their assigned students
- Multiple Export Formats: Supports JSON and XML output formats
- Command Line Interface: Easy-to-use CLI with proper argument parsing
- SOLID Principles: Clean, maintainable, and extensible code architecture
- Type Safety: Full type hints for better code reliability
- Python 3.7+
dicttoxmllibrary (for XML export)
-
Clone the repository:
git clone <repository-url> cd JSON-reader
-
Install dependencies:
pip3 install dicttoxml
JSON-reader/
├── main.py # Main application entry point
├── constants/ # Application constants and enums
│ ├── __init__.py
│ └── constants.py
├── cli/ # Command-line interface configuration
│ ├── __init__.py
│ └── cli.py
├── models/ # Data models
│ ├── __init__.py
│ └── models.py # Student and Room data models
├── loader/ # Data loading functionality
│ ├── __init__.py
│ └── data_loader.py # Data loading implementations
├── data_methods/ # Data processing functionality
│ ├── __init__.py
│ ├── data_combiner.py # Data combination logic
│ └── data_processor.py # Data processing utilities
├── exporter/ # Export functionality
│ ├── __init__.py
│ ├── base.py # Abstract exporter base class
│ ├── json_exporter.py # JSON export implementation
│ └── xml_exporter.py # XML export implementation
├── examples_json/ # Sample input data
│ ├── students.json # Sample student data
│ └── rooms.json # Sample room data
├── output/ # Generated output files
│ ├── combined.json # Sample JSON output
│ └── combined.xml # Sample XML output
└── README.md # This file
The application accepts the following command-line arguments:
python3 main.py --rooms ROOMS_FILE --students STUDENTS_FILE --format {json,xml} --output OUTPUT_FILE--rooms: Path to the rooms JSON file (required)--students: Path to the students JSON file (required)--format: Output format - either "json" or "xml" (required)--output: Path for the output file (required)
Export as JSON:
python3 main.py --rooms examples_json/rooms.json --students examples_json/students.json --format json --output combined.jsonExport as XML:
python3 main.py --rooms examples_json/rooms.json --students examples_json/students.json --format xml --output combined.xmlView help:
python3 main.py --helpstudents.json:
[
{
"id": 0,
"name": "John Doe",
"room": 101
}
]rooms.json:
[
{
"id": 101,
"name": "Room #101"
}
]JSON Output:
[
{
"id": 101,
"name": "Room #101",
"students": [
{
"id": 0,
"name": "John Doe",
"room": 101
}
]
}
]XML Output:
<?xml version="1.0" encoding="UTF-8" ?>
<rooms>
<item>
<id>101</id>
<name>Room #101</name>
<students>
<item>
<id>0</id>
<name>John Doe</name>
<room>101</room>
</item>
</students>
</item>
</rooms>The application follows SOLID principles and clean architecture:
-
Data Models (
models.py)Student: Represents student dataRoom: Represents room data with associated students
-
Data Loading (
loader/data_loader.py)DataLoader: Abstract base class for data loadingJsonDataLoader: Concrete implementation for JSON files
-
Data Processing (
data_methods/data_combiner.py)DataCombiner: Combines room and student data
-
CLI Configuration (
cli/cli.py)- Centralized argument parsing and CLI setup
-
Constants and Enums (
constants/constants.py)- Shared enums, directory names, messages, and other constants
-
Data Export (
exporter/)Exporter: Abstract base class for data exportJsonExporter: JSON export implementationXmlExporter: XML export implementation
- Single Responsibility: Each class has one clear purpose
- Open/Closed: Easy to extend with new export formats or data sources
- Liskov Substitution: Concrete implementations can substitute abstract classes
- Interface Segregation: Clean, focused interfaces
- Dependency Inversion: High-level modules depend on abstractions
The application has been tested with:
- Valid JSON input files
- Both JSON and XML export formats
- Command-line argument parsing
- Error handling for missing files
- Data combination logic
The repository includes sample data files:
examples_json/students.json: Contains 10,000+ student recordsexamples_json/rooms.json: Contains 1,000 room recordsoutput/combined.json: Sample JSON outputoutput/combined.xml: Sample XML output