A PHP 8.4+ library for converting JSON data to typed entities and back, with support for lazy-loading collections, mutable data structures, and structured entity design. Useful for structured JSON APIs, configuration parsing, and object-based manipulation of hierarchical JSON data.
- Object-oriented JSON mapping
- Conversion from JSON to typed entities and back
- Lazy-loading collections for efficient memory usage
- Entity objects are mutable and can be freely modified after creation
- Strict type support with automatic casting
- Native support for nested structures and arrays
- Easy integration with configuration or API responses
composer require matraux/json-orm
version | PHP | Note |
---|---|---|
1.1.0 | 8.3+ | Initial commit |
1.2.0 | 8.4+ | Performance optimization |
1.3.0 | 8.4+ | Performance optimization |
1.4.1 | 8.4+ | 50%+ performance boost via metadata caching |
1.4.2 | 8.4+ | Entity & Metadata fix and optimization |
See Definitions for how to define your own entities and collections.
See Read for full reading examples.
use Matraux\JsonORM\Json\SimpleJsonReader;
// Load data from JSON string or file
$reader = SimpleJsonReader::fromString('[{"CUSTOM_ID":1,"name":"First"}]');
// Create typed collection from JSON
$collection = CommonCollection::create($reader);
$entity = $collection[0];
echo $entity->name; // "First"
See Write for writing examples.
// Create collection and insert entity
$collection = CommonCollection::create();
$entity = $collection->createEntity();
$entity->name = 'Example';
echo json_encode($collection);
// '[{"name":"Example"}]'
See Development for debug, test instructions, static analysis, and coding standards.
For bug reports and feature requests, please use the issue tracker.