Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/beste/json
A simple JSON helper to decode and encode JSON
https://github.com/beste/json
helper json php
Last synced: about 13 hours 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 (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-04-25T08:01:41.000Z (8 months ago)
- Last Synced: 2024-04-25T09:27:20.265Z (8 months ago)
- Topics: helper, json, php
- Language: PHP
- Homepage:
- Size: 56.6 KB
- Stars: 22
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# JSON
[![Current version](https://img.shields.io/packagist/v/beste/json.svg?logo=composer)](https://packagist.org/packages/beste/json)
[![Supported PHP version](https://img.shields.io/static/v1?logo=php&label=PHP&message=~7.4.0%20||%20~8.0.0%20||%20~8.1.0&color=777bb4)](https://packagist.org/packages/beste/json)
[![Tests](https://github.com/beste/json/workflows/Tests/badge.svg)](https://github.com/beste/json/actions)
[![Discord](https://img.shields.io/discord/807679292573220925.svg?color=7289da&logo=discord)](https://discord.gg/Yacm7unBsr)
[![Sponsor](https://img.shields.io/static/v1?logo=GitHub&label=Sponsor&message=%E2%9D%A4&color=ff69b4)](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
```