netresearch/jsonmapper
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
Netresearch/JsonMapper is a powerful PHP tool for mapping nested JSON data onto PHP classes. This package is designed to take data retrieved from a JSON web service and convert it into nested objects and arrays - utilizing your custom model classes. This function is similar to the SOAP parameter mapping offered by PHP's SoapClient
but designed specifically for JSON data. JsonMapper automatically maps JSON data onto class properties, converting them into the appropriate simple types or objects without relying on any schemas or imposing the need for any JSON-specific code in your model classes.
To use Netresearch/JsonMapper, you need to register an autoloader that supports PSR-0 compatible classes, create an instance of the JsonMapper
object, and then call either the map
or mapArray
method depending on your data. Below is an example of its usage in code:
require 'autoload.php';
$mapper = new JsonMapper();
$contactObject = $mapper->map($jsonContact, new Contact());
For mapping an array of objects:
require 'autoload.php';
$mapper = new JsonMapper();
$contactsArray = $mapper->mapArray(
$jsonContacts, array(), 'Contact'
);
Implementations allow you to map JSON data onto complex object structures with useful type detection, error handling, as well as allowances for private properties and functions, and post-mapping callbacks.
The comprehensive documentation for netresearch/jsonmapper is enclosed within the Readme file of its GitHub repository at https://github.com/cweiske/jsonmapper.git. The Readme provides an in-depth coverage of the package's functions, featuring usage examples, parameter definitions, coding style guidelines, and more.