library json
A JSON encode/decode helper with easier error handling for PHP
tc/json
A JSON encode/decode helper with easier error handling for PHP
- Friday, March 3, 2017
- by carlcraig
- Repository
- 1 Watchers
- 1 Stars
- 5 Installations
- PHP
- 1 Dependents
- 0 Suggesters
- 0 Forks
- 0 Open issues
- 2 Versions
- 0 % Grown
Tc Json
A JSON encode/decode helper with easier error handling for PHP, (*1)
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., (*2)
See LICENSE for more details., (*3)