123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696 |
- --TEST--
- JSON (http://www.crockford.com/JSON/JSON_checker/test/pass1.json)
- --INI--
- serialize_precision=-1
- --FILE--
- <?php
- $test = "
- [
- \"JSON Test Pattern pass1\",
- {\"object with 1 member\":[\"array with 1 element\"]},
- {},
- [],
- -42,
- true,
- false,
- null,
- {
- \"integer\": 1234567890,
- \"real\": -9876.543210,
- \"e\": 0.123456789e-12,
- \"E\": 1.234567890E+34,
- \"\": 23456789012E666,
- \"zero\": 0,
- \"one\": 1,
- \"space\": \" \",
- \"quote\": \"\\\"\",
- \"backslash\": \"\\\\\",
- \"controls\": \"\\b\\f\\n\\r\\t\",
- \"slash\": \"/ & \\/\",
- \"alpha\": \"abcdefghijklmnopqrstuvwyz\",
- \"ALPHA\": \"ABCDEFGHIJKLMNOPQRSTUVWYZ\",
- \"digit\": \"0123456789\",
- \"special\": \"`1~!@#$%^&*()_+-={':[,]}|;.</>?\",
- \"hex\": \"\\u0123\\u4567\\u89AB\\uCDEF\\uabcd\\uef4A\",
- \"true\": true,
- \"false\": false,
- \"null\": null,
- \"array\":[ ],
- \"object\":{ },
- \"address\": \"50 St. James Street\",
- \"url\": \"http://www.JSON.org/\",
- \"comment\": \"// /* <!-- --\",
- \"# -- --> */\": \" \",
- \" s p a c e d \" :[1,2 , 3
- ,
- 4 , 5 , 6 ,7 ],
- \"compact\": [1,2,3,4,5,6,7],
- \"jsontext\": \"{\\\"object with 1 member\\\":[\\\"array with 1 element\\\"]}\",
- \"quotes\": \"" \\u0022 %22 0x22 034 "\",
- \"\\/\\\\\\\"\\uCAFE\\uBABE\\uAB98\\uFCDE\\ubcda\\uef4A\\b\\f\\n\\r\\t`1~!@#$%^&*()_+-=[]{}|;:',./<>?\"
- : \"A key can be any string\"
- },
- 0.5 ,98.6
- ,
- 99.44
- ,
- 1066
- ,\"rosebud\"]
- ";
- echo 'Testing:' . $test . "\n";
- echo "DECODE: AS OBJECT\n";
- $obj = json_decode($test);
- var_dump($obj);
- echo "DECODE: AS ARRAY\n";
- $arr = json_decode($test, true);
- var_dump($arr);
- echo "ENCODE: FROM OBJECT\n";
- $obj_enc = json_encode($obj, JSON_PARTIAL_OUTPUT_ON_ERROR);
- echo $obj_enc . "\n";
- echo "ENCODE: FROM ARRAY\n";
- $arr_enc = json_encode($arr, JSON_PARTIAL_OUTPUT_ON_ERROR);
- echo $arr_enc . "\n";
- echo "DECODE AGAIN: AS OBJECT\n";
- $obj = json_decode($obj_enc);
- var_dump($obj);
- echo "DECODE AGAIN: AS ARRAY\n";
- $arr = json_decode($arr_enc, true);
- var_dump($arr);
- ?>
- --EXPECT--
- Testing:
- [
- "JSON Test Pattern pass1",
- {"object with 1 member":["array with 1 element"]},
- {},
- [],
- -42,
- true,
- false,
- null,
- {
- "integer": 1234567890,
- "real": -9876.543210,
- "e": 0.123456789e-12,
- "E": 1.234567890E+34,
- "": 23456789012E666,
- "zero": 0,
- "one": 1,
- "space": " ",
- "quote": "\"",
- "backslash": "\\",
- "controls": "\b\f\n\r\t",
- "slash": "/ & \/",
- "alpha": "abcdefghijklmnopqrstuvwyz",
- "ALPHA": "ABCDEFGHIJKLMNOPQRSTUVWYZ",
- "digit": "0123456789",
- "special": "`1~!@#$%^&*()_+-={':[,]}|;.</>?",
- "hex": "\u0123\u4567\u89AB\uCDEF\uabcd\uef4A",
- "true": true,
- "false": false,
- "null": null,
- "array":[ ],
- "object":{ },
- "address": "50 St. James Street",
- "url": "http://www.JSON.org/",
- "comment": "// /* <!-- --",
- "# -- --> */": " ",
- " s p a c e d " :[1,2 , 3
- ,
- 4 , 5 , 6 ,7 ],
- "compact": [1,2,3,4,5,6,7],
- "jsontext": "{\"object with 1 member\":[\"array with 1 element\"]}",
- "quotes": "" \u0022 %22 0x22 034 "",
- "\/\\\"\uCAFE\uBABE\uAB98\uFCDE\ubcda\uef4A\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',./<>?"
- : "A key can be any string"
- },
- 0.5 ,98.6
- ,
- 99.44
- ,
- 1066
- ,"rosebud"]
- DECODE: AS OBJECT
- array(14) {
- [0]=>
- string(23) "JSON Test Pattern pass1"
- [1]=>
- object(stdClass)#1 (1) {
- ["object with 1 member"]=>
- array(1) {
- [0]=>
- string(20) "array with 1 element"
- }
- }
- [2]=>
- object(stdClass)#2 (0) {
- }
- [3]=>
- array(0) {
- }
- [4]=>
- int(-42)
- [5]=>
- bool(true)
- [6]=>
- bool(false)
- [7]=>
- NULL
- [8]=>
- object(stdClass)#3 (31) {
- ["integer"]=>
- int(1234567890)
- ["real"]=>
- float(-9876.54321)
- ["e"]=>
- float(1.23456789E-13)
- ["E"]=>
- float(1.23456789E+34)
- [""]=>
- float(INF)
- ["zero"]=>
- int(0)
- ["one"]=>
- int(1)
- ["space"]=>
- string(1) " "
- ["quote"]=>
- string(1) """
- ["backslash"]=>
- string(1) "\"
- ["controls"]=>
- string(5) "
-
"
- ["slash"]=>
- string(5) "/ & /"
- ["alpha"]=>
- string(25) "abcdefghijklmnopqrstuvwyz"
- ["ALPHA"]=>
- string(25) "ABCDEFGHIJKLMNOPQRSTUVWYZ"
- ["digit"]=>
- string(10) "0123456789"
- ["special"]=>
- string(31) "`1~!@#$%^&*()_+-={':[,]}|;.</>?"
- ["hex"]=>
- string(17) "ģ䕧覫췯ꯍ"
- ["true"]=>
- bool(true)
- ["false"]=>
- bool(false)
- ["null"]=>
- NULL
- ["array"]=>
- array(0) {
- }
- ["object"]=>
- object(stdClass)#4 (0) {
- }
- ["address"]=>
- string(19) "50 St. James Street"
- ["url"]=>
- string(20) "http://www.JSON.org/"
- ["comment"]=>
- string(13) "// /* <!-- --"
- ["# -- --> */"]=>
- string(1) " "
- [" s p a c e d "]=>
- array(7) {
- [0]=>
- int(1)
- [1]=>
- int(2)
- [2]=>
- int(3)
- [3]=>
- int(4)
- [4]=>
- int(5)
- [5]=>
- int(6)
- [6]=>
- int(7)
- }
- ["compact"]=>
- array(7) {
- [0]=>
- int(1)
- [1]=>
- int(2)
- [2]=>
- int(3)
- [3]=>
- int(4)
- [4]=>
- int(5)
- [5]=>
- int(6)
- [6]=>
- int(7)
- }
- ["jsontext"]=>
- string(49) "{"object with 1 member":["array with 1 element"]}"
- ["quotes"]=>
- string(27) "" " %22 0x22 034 ""
- ["/\"쫾몾ꮘﳞ볚
-
`1~!@#$%^&*()_+-=[]{}|;:',./<>?"]=>
- string(23) "A key can be any string"
- }
- [9]=>
- float(0.5)
- [10]=>
- float(98.6)
- [11]=>
- float(99.44)
- [12]=>
- int(1066)
- [13]=>
- string(7) "rosebud"
- }
- DECODE: AS ARRAY
- array(14) {
- [0]=>
- string(23) "JSON Test Pattern pass1"
- [1]=>
- array(1) {
- ["object with 1 member"]=>
- array(1) {
- [0]=>
- string(20) "array with 1 element"
- }
- }
- [2]=>
- array(0) {
- }
- [3]=>
- array(0) {
- }
- [4]=>
- int(-42)
- [5]=>
- bool(true)
- [6]=>
- bool(false)
- [7]=>
- NULL
- [8]=>
- array(31) {
- ["integer"]=>
- int(1234567890)
- ["real"]=>
- float(-9876.54321)
- ["e"]=>
- float(1.23456789E-13)
- ["E"]=>
- float(1.23456789E+34)
- [""]=>
- float(INF)
- ["zero"]=>
- int(0)
- ["one"]=>
- int(1)
- ["space"]=>
- string(1) " "
- ["quote"]=>
- string(1) """
- ["backslash"]=>
- string(1) "\"
- ["controls"]=>
- string(5) "
-
"
- ["slash"]=>
- string(5) "/ & /"
- ["alpha"]=>
- string(25) "abcdefghijklmnopqrstuvwyz"
- ["ALPHA"]=>
- string(25) "ABCDEFGHIJKLMNOPQRSTUVWYZ"
- ["digit"]=>
- string(10) "0123456789"
- ["special"]=>
- string(31) "`1~!@#$%^&*()_+-={':[,]}|;.</>?"
- ["hex"]=>
- string(17) "ģ䕧覫췯ꯍ"
- ["true"]=>
- bool(true)
- ["false"]=>
- bool(false)
- ["null"]=>
- NULL
- ["array"]=>
- array(0) {
- }
- ["object"]=>
- array(0) {
- }
- ["address"]=>
- string(19) "50 St. James Street"
- ["url"]=>
- string(20) "http://www.JSON.org/"
- ["comment"]=>
- string(13) "// /* <!-- --"
- ["# -- --> */"]=>
- string(1) " "
- [" s p a c e d "]=>
- array(7) {
- [0]=>
- int(1)
- [1]=>
- int(2)
- [2]=>
- int(3)
- [3]=>
- int(4)
- [4]=>
- int(5)
- [5]=>
- int(6)
- [6]=>
- int(7)
- }
- ["compact"]=>
- array(7) {
- [0]=>
- int(1)
- [1]=>
- int(2)
- [2]=>
- int(3)
- [3]=>
- int(4)
- [4]=>
- int(5)
- [5]=>
- int(6)
- [6]=>
- int(7)
- }
- ["jsontext"]=>
- string(49) "{"object with 1 member":["array with 1 element"]}"
- ["quotes"]=>
- string(27) "" " %22 0x22 034 ""
- ["/\"쫾몾ꮘﳞ볚
-
`1~!@#$%^&*()_+-=[]{}|;:',./<>?"]=>
- string(23) "A key can be any string"
- }
- [9]=>
- float(0.5)
- [10]=>
- float(98.6)
- [11]=>
- float(99.44)
- [12]=>
- int(1066)
- [13]=>
- string(7) "rosebud"
- }
- ENCODE: FROM OBJECT
- ["JSON Test Pattern pass1",{"object with 1 member":["array with 1 element"]},{},[],-42,true,false,null,{"integer":1234567890,"real":-9876.54321,"e":1.23456789e-13,"E":1.23456789e+34,"":0,"zero":0,"one":1,"space":" ","quote":"\"","backslash":"\\","controls":"\b\f\n\r\t","slash":"\/ & \/","alpha":"abcdefghijklmnopqrstuvwyz","ALPHA":"ABCDEFGHIJKLMNOPQRSTUVWYZ","digit":"0123456789","special":"`1~!@#$%^&*()_+-={':[,]}|;.<\/>?","hex":"\u0123\u4567\u89ab\ucdef\uabcd\uef4a","true":true,"false":false,"null":null,"array":[],"object":{},"address":"50 St. James Street","url":"http:\/\/www.JSON.org\/","comment":"\/\/ \/* <!-- --","# -- --> *\/":" "," s p a c e d ":[1,2,3,4,5,6,7],"compact":[1,2,3,4,5,6,7],"jsontext":"{\"object with 1 member\":[\"array with 1 element\"]}","quotes":"" \" %22 0x22 034 "","\/\\\"\ucafe\ubabe\uab98\ufcde\ubcda\uef4a\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',.\/<>?":"A key can be any string"},0.5,98.6,99.44,1066,"rosebud"]
- ENCODE: FROM ARRAY
- ["JSON Test Pattern pass1",{"object with 1 member":["array with 1 element"]},[],[],-42,true,false,null,{"integer":1234567890,"real":-9876.54321,"e":1.23456789e-13,"E":1.23456789e+34,"":0,"zero":0,"one":1,"space":" ","quote":"\"","backslash":"\\","controls":"\b\f\n\r\t","slash":"\/ & \/","alpha":"abcdefghijklmnopqrstuvwyz","ALPHA":"ABCDEFGHIJKLMNOPQRSTUVWYZ","digit":"0123456789","special":"`1~!@#$%^&*()_+-={':[,]}|;.<\/>?","hex":"\u0123\u4567\u89ab\ucdef\uabcd\uef4a","true":true,"false":false,"null":null,"array":[],"object":[],"address":"50 St. James Street","url":"http:\/\/www.JSON.org\/","comment":"\/\/ \/* <!-- --","# -- --> *\/":" "," s p a c e d ":[1,2,3,4,5,6,7],"compact":[1,2,3,4,5,6,7],"jsontext":"{\"object with 1 member\":[\"array with 1 element\"]}","quotes":"" \" %22 0x22 034 "","\/\\\"\ucafe\ubabe\uab98\ufcde\ubcda\uef4a\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',.\/<>?":"A key can be any string"},0.5,98.6,99.44,1066,"rosebud"]
- DECODE AGAIN: AS OBJECT
- array(14) {
- [0]=>
- string(23) "JSON Test Pattern pass1"
- [1]=>
- object(stdClass)#5 (1) {
- ["object with 1 member"]=>
- array(1) {
- [0]=>
- string(20) "array with 1 element"
- }
- }
- [2]=>
- object(stdClass)#6 (0) {
- }
- [3]=>
- array(0) {
- }
- [4]=>
- int(-42)
- [5]=>
- bool(true)
- [6]=>
- bool(false)
- [7]=>
- NULL
- [8]=>
- object(stdClass)#7 (31) {
- ["integer"]=>
- int(1234567890)
- ["real"]=>
- float(-9876.54321)
- ["e"]=>
- float(1.23456789E-13)
- ["E"]=>
- float(1.23456789E+34)
- [""]=>
- int(0)
- ["zero"]=>
- int(0)
- ["one"]=>
- int(1)
- ["space"]=>
- string(1) " "
- ["quote"]=>
- string(1) """
- ["backslash"]=>
- string(1) "\"
- ["controls"]=>
- string(5) "
-
"
- ["slash"]=>
- string(5) "/ & /"
- ["alpha"]=>
- string(25) "abcdefghijklmnopqrstuvwyz"
- ["ALPHA"]=>
- string(25) "ABCDEFGHIJKLMNOPQRSTUVWYZ"
- ["digit"]=>
- string(10) "0123456789"
- ["special"]=>
- string(31) "`1~!@#$%^&*()_+-={':[,]}|;.</>?"
- ["hex"]=>
- string(17) "ģ䕧覫췯ꯍ"
- ["true"]=>
- bool(true)
- ["false"]=>
- bool(false)
- ["null"]=>
- NULL
- ["array"]=>
- array(0) {
- }
- ["object"]=>
- object(stdClass)#8 (0) {
- }
- ["address"]=>
- string(19) "50 St. James Street"
- ["url"]=>
- string(20) "http://www.JSON.org/"
- ["comment"]=>
- string(13) "// /* <!-- --"
- ["# -- --> */"]=>
- string(1) " "
- [" s p a c e d "]=>
- array(7) {
- [0]=>
- int(1)
- [1]=>
- int(2)
- [2]=>
- int(3)
- [3]=>
- int(4)
- [4]=>
- int(5)
- [5]=>
- int(6)
- [6]=>
- int(7)
- }
- ["compact"]=>
- array(7) {
- [0]=>
- int(1)
- [1]=>
- int(2)
- [2]=>
- int(3)
- [3]=>
- int(4)
- [4]=>
- int(5)
- [5]=>
- int(6)
- [6]=>
- int(7)
- }
- ["jsontext"]=>
- string(49) "{"object with 1 member":["array with 1 element"]}"
- ["quotes"]=>
- string(27) "" " %22 0x22 034 ""
- ["/\"쫾몾ꮘﳞ볚
-
`1~!@#$%^&*()_+-=[]{}|;:',./<>?"]=>
- string(23) "A key can be any string"
- }
- [9]=>
- float(0.5)
- [10]=>
- float(98.6)
- [11]=>
- float(99.44)
- [12]=>
- int(1066)
- [13]=>
- string(7) "rosebud"
- }
- DECODE AGAIN: AS ARRAY
- array(14) {
- [0]=>
- string(23) "JSON Test Pattern pass1"
- [1]=>
- array(1) {
- ["object with 1 member"]=>
- array(1) {
- [0]=>
- string(20) "array with 1 element"
- }
- }
- [2]=>
- array(0) {
- }
- [3]=>
- array(0) {
- }
- [4]=>
- int(-42)
- [5]=>
- bool(true)
- [6]=>
- bool(false)
- [7]=>
- NULL
- [8]=>
- array(31) {
- ["integer"]=>
- int(1234567890)
- ["real"]=>
- float(-9876.54321)
- ["e"]=>
- float(1.23456789E-13)
- ["E"]=>
- float(1.23456789E+34)
- [""]=>
- int(0)
- ["zero"]=>
- int(0)
- ["one"]=>
- int(1)
- ["space"]=>
- string(1) " "
- ["quote"]=>
- string(1) """
- ["backslash"]=>
- string(1) "\"
- ["controls"]=>
- string(5) "
-
"
- ["slash"]=>
- string(5) "/ & /"
- ["alpha"]=>
- string(25) "abcdefghijklmnopqrstuvwyz"
- ["ALPHA"]=>
- string(25) "ABCDEFGHIJKLMNOPQRSTUVWYZ"
- ["digit"]=>
- string(10) "0123456789"
- ["special"]=>
- string(31) "`1~!@#$%^&*()_+-={':[,]}|;.</>?"
- ["hex"]=>
- string(17) "ģ䕧覫췯ꯍ"
- ["true"]=>
- bool(true)
- ["false"]=>
- bool(false)
- ["null"]=>
- NULL
- ["array"]=>
- array(0) {
- }
- ["object"]=>
- array(0) {
- }
- ["address"]=>
- string(19) "50 St. James Street"
- ["url"]=>
- string(20) "http://www.JSON.org/"
- ["comment"]=>
- string(13) "// /* <!-- --"
- ["# -- --> */"]=>
- string(1) " "
- [" s p a c e d "]=>
- array(7) {
- [0]=>
- int(1)
- [1]=>
- int(2)
- [2]=>
- int(3)
- [3]=>
- int(4)
- [4]=>
- int(5)
- [5]=>
- int(6)
- [6]=>
- int(7)
- }
- ["compact"]=>
- array(7) {
- [0]=>
- int(1)
- [1]=>
- int(2)
- [2]=>
- int(3)
- [3]=>
- int(4)
- [4]=>
- int(5)
- [5]=>
- int(6)
- [6]=>
- int(7)
- }
- ["jsontext"]=>
- string(49) "{"object with 1 member":["array with 1 element"]}"
- ["quotes"]=>
- string(27) "" " %22 0x22 034 ""
- ["/\"쫾몾ꮘﳞ볚
-
`1~!@#$%^&*()_+-=[]{}|;:',./<>?"]=>
- string(23) "A key can be any string"
- }
- [9]=>
- float(0.5)
- [10]=>
- float(98.6)
- [11]=>
- float(99.44)
- [12]=>
- int(1066)
- [13]=>
- string(7) "rosebud"
- }
|