Phase 2: JSON/YAML Import Functionality
Phase 2: JSON/YAML Import Functionality
Objective
Enable XMD to import JSON and YAML files with unified data handling using libyaml and json-c libraries.
Tasks
1. JSON/YAML Parser Integration
- Add json-c dependency to CMakeLists.txt
- Create JSON parser wrapper
- Create YAML parser wrapper
- Implement unified data structure converter
2. Enhanced Import Directive
- Extend existing import functionality
- Add file type detection (json/yaml/yml)
- Create import processor for structured data
- Handle import errors gracefully
3. Data Structure Unification
- Define internal data representation
- Convert JSON objects to XMD variables
- Convert YAML maps to XMD variables
- Handle arrays and primitive types
4. Variable System Enhancement
- Support nested object access
- Add object property navigation
- Implement array indexing
- Create data type validation
File Structure
src/
โโโ import/
โ โโโ import_json/
โ โ โโโ import_json.c # JSON file import
โ โโโ import_yaml/
โ โ โโโ import_yaml.c # YAML file import
โ โโโ detect_file_type/
โ โ โโโ detect_file_type.c # File type detection
โ โโโ unified_data_converter/
โ โโโ unified_data_converter.c # Convert to XMD format
โโโ parsers/
โ โโโ json_parser/
โ โ โโโ json_parser.c # json-c wrapper
โ โโโ yaml_parser/
โ โ โโโ yaml_parser.c # libyaml wrapper (already exists)
โโโ data_structures/
โ โโโ xmd_object/
โ โ โโโ xmd_object.c # Object representation
โ โโโ xmd_array/
โ โ โโโ xmd_array.c # Array representation
โ โโโ data_converter/
โ โโโ data_converter.c # Type conversion utilities
Tests
- test/import/test_import_json.c
- test/import/test_import_yaml.c
- test/import/test_detect_file_type.c
- test/parsers/test_json_parser.c
- test/data_structures/test_xmd_object.c
- test/data_structures/test_xmd_array.c
Dependencies
- json-c for JSON parsing
- libyaml for YAML parsing (already added in phase 1)
- Existing import system
Data Format Examples
JSON Import
{
"name": "Alice",
"age": 30,
"skills": ["programming", "design"],
"address": {
"city": "New York",
"zip": "10001"
}
}
YAML Import
name: Alice
age: 30
skills:
- programming
- design
address:
city: New York
zip: "10001"
XMD Usage
Name:
Age:
First skill:
City:
Config value:
Acceptance Criteria
- Import JSON files with
import "file.json" as varname - Import YAML files with
import "file.yaml" as varname - Access nested properties with dot notation
- Access array elements with bracket notation
- Both JSON and YAML create identical XMD data structures
- Comprehensive error handling for malformed files
- Memory management for imported data structures
- All functions follow one-function-per-file rule
- Complete test coverage
- Backward compatibility with existing import system