sanchescom / json-helper
This library provides helper functions for working with json.
Installs: 4 012
Dependents: 1
Suggesters: 0
Security: 0
Stars: 4
Watchers: 1
Forks: 1
Open Issues: 0
Requires
- php: ^7.2
- ext-json: *
Requires (Dev)
- mockery/mockery: ^1.2
- phpunit/phpunit: ^8.0
- squizlabs/php_codesniffer: ^3.4
This package is auto-updated.
Last update: 2024-11-21 22:29:26 UTC
README
This library provides helper functions for working with json.
Installing
Require this package, with Composer, in the root directory of your project.
$ composer require sanchescom/json-helper
Usage
<?php require_once './vendor/autoload.php'; use Sanchescom\Support\Json; use Sanchescom\Support\Exceptions\JsonException; class Character { public $name; } try { /** * stdClass Object * ( * [name] => Tom * ) */ $json = Json::decode('{"name": "Tom"}'); /** * Array * ( * [name] => Tom * ) */ $array = Json::asArray('{"name": "Tom"}'); /** * Character Object * ( * [name] => Tom * ) */ $instance = Json::asInstanceOf(Character::class, '{"name": "Tom"}'); /** * Array * ( * [0] => Character Object * ( * [name] => Tom * ) * [1] => Character Object * ( * [name] => Jerry * ) * ) */ $collection = Json::asCollectionOfInstances(Character::class, '[{"name": "Tom"}, {"name": "Jerry"}]'); /** * $valid = true */ $valid = Json::isValid('{"data":"Hello World"}'); /** * $valid = false */ $invalid = Json::isValid('{1}'); } catch (JsonException $e) { echo $e->getMessage(); } catch (ReflectionException $e) { echo $e->getMessage(); }
Contributing
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
Versioning
We use SemVer for versioning. For the versions available, see the tags on this repository.
Authors
- Efimov Aleksandr - Initial work - Sanchescom
See also the list of contributors who participated in this project.
License
This project is licensed under the MIT License - see the LICENSE.md file for details