tc / json
A JSON encode/decode helper with easier error handling for PHP
v1.0.0
2017-03-03 22:21 UTC
Requires
- php: >=5.5.0
This package is not auto-updated.
Last update: 2025-03-02 04:22:23 UTC
README
A JSON encode/decode helper with easier error handling for PHP
Installation
composer require tc/json
Usage
<?php use Tc\Json\Json; use Tc\Json\JsonException; $data = [ 'foo' => 'bar', ]; $jsonString = Json::encode($data); // {"foo": "bar"} $jsonDataObject = Json::decode($jsonString); // ( [foo] => bar ) $jsonDataArray = Json::decode($jsonString, true ); // ['foo' => 'bar'] $jsonData = Json::decode($jsonString, true); // ['foo' => 'bar'] try { Json::decode('{"foo"'); // invalid json string } catch(JsonException $e) { echo $e->getMessage(); // description of error }
License
Tc Json is licensed with the MIT license.
See LICENSE for more details.