jedkirby/json

Maintainers

Details

github.com/jedkirby/json

Source

Issues

Installs: 151 224

Dependents: 2

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

Type:project

0.1.0 2019-04-17 15:37 UTC

This package is auto-updated.

Last update: 2024-11-06 03:39:05 UTC


README

This package is designed to bridge the gap between the default json_* methods, ensuring a fluent and easy to use structure.

Installation

This package can be installed via [Composer]:

$ composer require jedkirby/json

It requires PHP >= 7.0.0.

Usage

The following guide assumes that you've imported the class Jedkirby\Json into your namespace.

The Json constructor requires you to pass the exact same methods as the json_decode method, however, is provides additional functionality once initilised.

The following code should help explain using this package, thus providing the fluent and easy to use structure:

$json = new Json('{"name":"James Kirby"}');

if (false === $json->isValid()) {
    throw new RuntimeException(sprintf(
        'Parsing failed with error "%s"',
        $json->getErrorMessage()
    ));
}

return $json->getResponse();

Helpers

There's a couple of helper methods built in, which provide additional functionality, these are listed below:

Testing

Unit tests can be run within the package, however, it utilises Docker & Docker Compose:

$ docker-compose -f ./docker-compose.yml run --rm cli php ./vendor/bin/phpunit

License

jedkirby/json is licensed under the MIT license. See the LICENSE file for more details.