netresearch/jsonmapper
Map JSON to strongly-typed PHP objects with JSONMapper. Hydrate class properties from stdClass/arrays, support nested objects and collections, docblock/type-hint based mapping, and optional strict checking for missing or invalid fields.
Install via Composer: composer require netresearch/jsonmapper. Begin by creating simple PHP classes (POPOs) that mirror your JSON structure—JsonMapper auto-populates them using reflection. For a basic use case like deserializing a user response:
use JsonMapper;
class User {
public string $name;
public int $age;
}
$mapper = new JsonMapper();
$json = '{"name":"Alice","age":30}';
$user = $mapper->map(json_decode($json), new User());
// Access: $user->name === 'Alice'
Check README.md for core examples and docs/ (if available) for advanced patterns like custom factories.
config/*.json into typed config objects—improves validation and IDE support.$mapper->setPropertyNameStrategy(JsonMapper::PROPERTY_NAME_STRATEGY_CAMEL_CASE);
EVENT_BEFORE_MAP/EVENT_AFTER_MAP for validation or logging.JsonMapper to customize mapObject() for domain-specific types (e.g., enums, UUIDs).JsonMapperFactory for DI-friendly setup (e.g., injecting custom handlers in Laravel).public properties or protected properties with @var annotations are mapped. Private properties require a custom setter strategy.public string $email; triggers error if missing) or defaults (e.g., public ?string $token = null;).JsonMapper lacks cycle detection—avoid recursive structures or pre-flatten JSON to prevent memory exhaustion.JsonMapper instances (stateless), and avoid heavy annotation use; while reflection caching helps, tight loops need benchmarking.symfony/validator or custom @Assert-style annotations if needed.How can I help you explore Laravel packages today?