phpninjas / json
Installs: 19
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/phpninjas/json
Requires
- php: >=5.4
Requires (Dev)
- phpunit/phpunit: ~4.8
This package is not auto-updated.
Last update: 2025-10-01 15:01:09 UTC
README
Get Composer
curl -sS https://getcomposer.org/installer | php
php composer.phar install
composer.json
{ "require": { "phpninjas/json": "v0.1.0" } }
JSON Library
A simple wrapper around the json_encode and json_decode functions that handle errors with exceptions as opposed to using the built-in functions from PHP.
Encoding
Turn a php variable into a json string (and throw an error during failure).
<?php use phpninjas\JSON\JSON; use phpninjas\JSON\JsonEncodingException; try { $jsonString = JSON::encode($var); }catch(JsonEncodingException $e){ // handle exception }
Decoding
Turn a JSON string into a php variable (and throw an error during failure).
<?php use phpninjas\JSON\JSON; use phpninjas\JSON\JsonDecodingException; try { $var = JSON::decode($jsonString); }catch(JsonDecodingException $e){ // handle exception }