https://github.com/kapitanluffy/json-object
Treat JSON as objects in PHP instead of strings.
https://github.com/kapitanluffy/json-object
json php
Last synced: about 2 months ago
JSON representation
Treat JSON as objects in PHP instead of strings.
- Host: GitHub
- URL: https://github.com/kapitanluffy/json-object
- Owner: kapitanluffy
- License: mpl-2.0
- Created: 2018-04-26T03:50:03.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2018-04-26T04:01:14.000Z (about 7 years ago)
- Last Synced: 2025-02-07T03:25:40.502Z (3 months ago)
- Topics: json, php
- Language: PHP
- Size: 6.84 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PHP JSON Objects
Treat JSON as objects in PHP instead of strings.
##### Install
```
composer require kapitanluffy/json-object
```##### Usage
```php
$json = new JsonObject($data);// encoding to json
$encoded = json_encode($json);
$encoded = $json->encode();
$encoded = (string) $json;// decoding to data
$decoded = JsonObject::decode($json);// set options
$json->options(JSON_NUMERIC_CHECK)->encode();// throw a JsonException on error
$json->withErrors(true)->encode();// check if the current instance throws an error
$json->isErrorThrown();// returns the last occurred JsonException
JsonObject::getError();
```Note that methods `options` and `withErrors` returns a new instance rather than modifying the current JsonObject instance.