tc/json

A JSON encode/decode helper with easier error handling for PHP

v1.0.0 2017-03-03 22:21 UTC

This package is not auto-updated.

Last update: 2024-05-12 00:32:35 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.