Skip to content

Latest commit

 

History

History
139 lines (107 loc) · 3.22 KB

README.md

File metadata and controls

139 lines (107 loc) · 3.22 KB

JSONLite is a lite version of JSON.

PHP 5.2 or later

Build Status

feature

  • 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

examples

$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,
  * )
  */

version

  • latest update: 2014-12-25
  • latest version: 0.2

install

    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

size

mode json jsonlite saving rate
array_js92920 0.00%
array_strict9274-1819.57%
array_min9270-2223.91%
map_js11197-1412.61%
map_strict11183-2825.23%
map_min11181-3027.03%

forms

map/object

array

value

number

string

contact

email: system128/at/gmail/dot/com