JSONLite is a lite version of JSON.
PHP 5.2 or later
- encode
- mode : js. Compatible with javascript
- mode : strict. Keep the data type
- ex. 1.0 will be encode as "1.0"(without quote),and decode as 1.0
- encode mode : min. Reduce the data size, which is useful for logs.
- decode : Compatible with JSON
- Better error position brief and description
- Make errors more explicit
$value = array(
'code' => '123',
'msg' => 'true str',
'null' => null,
'new' => '',
'double' => 1.0,
);
// serialize
// js
echo jsonlite_encode($value);
// {code:123,msg:"true str","null":0,"new":"",double:1}
// min
echo jsonlite_encode($value, JSONLITE_MODE_MIN);
// {code:123,msg:true str,"null":,new:,double:1}
// strict
echo jsonlite_encode($value, JSONLITE_MODE_STRICT);
// {code:"123",msg:true str,"null":null,new:,double:1.0}
// unserialize
$jsonlite = '{code:123,msg:true str,"null":null,new:,double:1}';
$value = jsonlite_decode($jsonlite);
var_export($value);
/**
* array (
* 'code' => 123,
* 'msg' => 'true str',
* 'null' => NULL,
* 'new' => '',
* 'double' => 1,
* )
*/
// work with json
$value = array(
'code' => '123',
'msg' => 'true str',
'null' => null,
'new' => '',
'double' => 1.0,
);
$json = json_encode($value); // ATTENTION:encode with json
// {"code":"123","msg":"true str","null":null,"new":"","double":1}
$value = jsonlite_decode($json);
var_export($value);
/**
* array (
* 'code' => 123,
* 'msg' => 'true str',
* 'null' => NULL,
* 'new' => '',
* 'double' => 1,
* )
*/
- latest update: 2014-12-25
- latest version: 0.2
user$ git clone git://github.com/eixom/php-jsonlite.git
user$ cd php-jsonlite
user$ ~/your/php/bin/phpize
user$ ./configure --with-php-config=~/your/php/bin/php-config
user$ make
user$ make install
mode | json | jsonlite | saving | rate |
array_js | 92 | 92 | 0 | 0.00% |
array_strict | 92 | 74 | -18 | 19.57% |
array_min | 92 | 70 | -22 | 23.91% |
map_js | 111 | 97 | -14 | 12.61% |
map_strict | 111 | 83 | -28 | 25.23% |
map_min | 111 | 81 | -30 | 27.03% |
email: system128/at/gmail/dot/com