Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jannejava/json
A simple wrapper around json_encode() and json_decode() for catching any errors without executing json_last_error()
https://github.com/jannejava/json
json laravel
Last synced: 3 months ago
JSON representation
A simple wrapper around json_encode() and json_decode() for catching any errors without executing json_last_error()
- Host: GitHub
- URL: https://github.com/jannejava/json
- Owner: jannejava
- License: mit
- Created: 2018-05-10T20:21:54.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-05-07T07:17:21.000Z (6 months ago)
- Last Synced: 2024-07-18T19:10:20.273Z (4 months ago)
- Topics: json, laravel
- Language: PHP
- Homepage: https://eastwest.se
- Size: 36.1 KB
- Stars: 93
- Watchers: 2
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Wrap JSON encoding/decoding errors in exception
Catch `json_encode()` and `json_decode()` errors without executing `json_last_error()`. In PHP 7.3 these functions will [throw an exception](https://laravel-news.com/php-7-3-json-error-handling).
```php
use Eastwest\Json\Json;
use Eastwest\Json\JsonException;try {
$json = Json::encode(['key' => 'value']);
} catch (JsonException $e) {
// code and message will match json_last_error() values:
// @link http://php.net/manual/en/function.json-last-error.php#refsect1-function.json-last-error-returnvalues
echo $e->getMessage();
echo $e->getCode();
}
```## Installation
You'll have to follow a couple of simple steps to install this package.### Downloading
Via [composer](http://getcomposer.org):```bash
$ composer require eastwest/json:^3.0
```Or add the package to your development dependencies in `composer.json` and run
`composer update eastwest/json` to download the package:```json
{
"require": {
"eastwest/json": "^3.0"
}
}
```*If you need a way to deploy files or manage your Laravel Forge servers. Take a look at [GitFTP-Deploy](https://gitftp-deploy.com) or [F-Bar](https://laravel-forge-menubar.com)*