Skip to content

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

License

Notifications You must be signed in to change notification settings

carlcraig/tc-json

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tc Json

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.

About

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages