Giter Site home page Giter Site logo

php-jsonlite's Introduction

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

php-jsonlite's People

Contributors

eixom avatar

Watchers

James Cloos avatar jingdor avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.