https://github.com/beste/json
A simple JSON helper to decode and encode JSON
https://github.com/beste/json
helper json php
Last synced: 11 months ago
JSON representation
A simple JSON helper to decode and encode JSON
- Host: GitHub
- URL: https://github.com/beste/json
- Owner: beste
- License: mit
- Created: 2022-02-12T21:18:55.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2025-05-12T07:36:30.000Z (about 1 year ago)
- Last Synced: 2025-06-20T04:04:01.325Z (about 1 year ago)
- Topics: helper, json, php
- Language: PHP
- Homepage:
- Size: 84 KB
- Stars: 33
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# JSON
[](https://packagist.org/packages/beste/json)
[](https://packagist.org/packages/beste/json)
[](https://github.com/beste/json/actions)
[](https://discord.gg/Yacm7unBsr)
[](https://github.com/sponsors/jeromegamez)
A simple helper to decode and encode JSON, including from files.
## Usage
```php
use Beste\Json;
use UnexpectedValueException;
$object = Json::decode('{"key": "value"}');
$array = Json::decode('{"key": "value"}', $forceArray = true);
$object = Json::decodeFile('/path/to/file.json');
$json = Json::encode($object);
$prettyJson = Json::pretty($object);
// When something goes wring while decoding/encoding,
// an `UnexpectedValueException` is thrown
try {
Json::decode('{]');
} catch (UnexpectedValueException $e) {
// Handle error
}
```
## Installation
```shell
composer require beste/json
```
## Running tests
```shell
composer test
```