https://github.com/bpolaszek/php-lib-json
JSON convenience library written in PHP
https://github.com/bpolaszek/php-lib-json
Last synced: 3 months ago
JSON representation
JSON convenience library written in PHP
- Host: GitHub
- URL: https://github.com/bpolaszek/php-lib-json
- Owner: bpolaszek
- License: apache-2.0
- Created: 2017-02-08T10:10:35.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2016-03-25T13:54:13.000Z (almost 10 years ago)
- Last Synced: 2025-10-04T12:05:49.799Z (3 months ago)
- Language: PHP
- Homepage:
- Size: 32.2 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.md
- License: COPYING
Awesome Lists containing this project
README
[](https://travis-ci.org/fkooman/php-lib-json)
[](https://scrutinizer-ci.com/g/fkooman/php-lib-json/?branch=master)
# Introduction
This is a PHP library written to make it easy and safe to process JSON. It will
throw exceptions when encoding or decoding fails.
# Installation
You can use [Composer](https://getcomposer.org) and require `fkooman/json` to
use this library in your application.
# Tests
You can run the PHPUnit tests if PHPUnit is installed:
$ phpunit
Do not forget to run `/path/to/composer.phar install` first.
# API
To use the library, see the example below:
'bar')) . PHP_EOL;
echo var_export(Json::decode('{"foo":"bar"}')) . PHP_EOL;
try {
Json::decode('{');
} catch (JsonException $e) {
echo "ERROR: " . $e->getMessage(). PHP_EOL;
}
This will output the following:
"foo"
{"foo":"bar"}
array (
'foo' => 'bar',
)
ERROR: Syntax error
If you want to use encoding parameters of the original `json_encode()` you can
use them "as is" as the second parameter to `Json::encode()`. By default this
library returns arrays when decoding JSON. If you want to for objects make the
second parameter of `Json::decode()` `false`.
# License
Licensed under the Apache License, Version 2.0;
http://www.apache.org/licenses/LICENSE-2.0