Skip to content

Files

Latest commit

Apr 14, 2014
3970b9d · Apr 14, 2014

History

History
This branch is 1 commit ahead of, 61104 commits behind php/php-src:master.

json

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Apr 14, 2014
Apr 2, 2009
Feb 9, 2011
Jun 23, 2012
Jan 31, 2006
Nov 25, 2012
Nov 25, 2012
Apr 14, 2014
Apr 28, 2010
Mar 18, 2006
Feb 17, 2014
Jan 2, 2009
Jan 31, 2006
json 1.2.0
==========

This extension implements the JavaScript Object Notation (JSON)
data-interchange format as specified in [0].

Two functions are implemented: encoding and decoding. The decoding
is handled by a parser based on JSON_checker[1] by Douglas Crockford.


Function overview
-----------------

    string json_encode ( mixed value )

json_encode returns a string containing the JSON representation of value.
value can be any type except a resource.

    mixed json_decode ( string json, [bool assoc] )

json_decode takes a JSON string and converts it into a PHP variable.
When assoc is given, and evaluates to TRUE, json_decode() will return
any objects as associative arrays.


Example usage
-------------

$arr = array("a"=>1,"b"=>2,"c"=>3,"d"=>4,"e"=>5);
echo json_encode($arr);

---> {"a":1,"b":2,"c":3,"d":4,"e":5}

$json = '{"a":1,"b":2,"c":3,"d":4,"e":5}';
var_dump(json_decode($json));

---> object(stdClass)#1 (5) {
        ["a"]=>
        int(1)
        ["b"]=>
        int(2)
        ["c"]=>
        int(3)
        ["d"]=>
        int(4)
        ["e"]=>
        int(5)
     }

$json = '{"a":1,"b":2,"c":3,"d":4,"e":5}';
var_dump(json_decode($json, true));

---> array(5) {
        ["a"]=>
        int(1)
        ["b"]=>
        int(2)
        ["c"]=>
        int(3)
        ["d"]=>
        int(4)
        ["e"]=>
        int(5)
     }


Authors
-------

Omar Kilani <omar@php.net>


---

[0] http://www.crockford.com/JSON/draft-jsonorg-json-00.txt
[1] http://www.crockford.com/JSON/JSON_checker/