1--TEST-- 2JSON (http://www.crockford.com/JSON/JSON_checker/test/pass1.json) 3--INI-- 4serialize_precision=-1 5--SKIPIF-- 6<?php 7if (!extension_loaded('json')) die('skip'); 8?> 9--FILE-- 10<?php 11 12$test = " 13[ 14 \"JSON Test Pattern pass1\", 15 {\"object with 1 member\":[\"array with 1 element\"]}, 16 {}, 17 [], 18 -42, 19 true, 20 false, 21 null, 22 { 23 \"integer\": 1234567890, 24 \"real\": -9876.543210, 25 \"e\": 0.123456789e-12, 26 \"E\": 1.234567890E+34, 27 \"\": 23456789012E666, 28 \"zero\": 0, 29 \"one\": 1, 30 \"space\": \" \", 31 \"quote\": \"\\\"\", 32 \"backslash\": \"\\\\\", 33 \"controls\": \"\\b\\f\\n\\r\\t\", 34 \"slash\": \"/ & \\/\", 35 \"alpha\": \"abcdefghijklmnopqrstuvwyz\", 36 \"ALPHA\": \"ABCDEFGHIJKLMNOPQRSTUVWYZ\", 37 \"digit\": \"0123456789\", 38 \"special\": \"`1~!@#$%^&*()_+-={':[,]}|;.</>?\", 39 \"hex\": \"\\u0123\\u4567\\u89AB\\uCDEF\\uabcd\\uef4A\", 40 \"true\": true, 41 \"false\": false, 42 \"null\": null, 43 \"array\":[ ], 44 \"object\":{ }, 45 \"address\": \"50 St. James Street\", 46 \"url\": \"http://www.JSON.org/\", 47 \"comment\": \"// /* <!-- --\", 48 \"# -- --> */\": \" \", 49 \" s p a c e d \" :[1,2 , 3 50 51, 52 534 , 5 , 6 ,7 ], 54 \"compact\": [1,2,3,4,5,6,7], 55 \"jsontext\": \"{\\\"object with 1 member\\\":[\\\"array with 1 element\\\"]}\", 56 \"quotes\": \"" \\u0022 %22 0x22 034 "\", 57 \"\\/\\\\\\\"\\uCAFE\\uBABE\\uAB98\\uFCDE\\ubcda\\uef4A\\b\\f\\n\\r\\t`1~!@#$%^&*()_+-=[]{}|;:',./<>?\" 58: \"A key can be any string\" 59 }, 60 0.5 ,98.6 61, 6299.44 63, 64 651066 66 67 68,\"rosebud\"] 69"; 70 71echo 'Testing: ' . $test . "\n"; 72echo "DECODE: AS OBJECT\n"; 73$obj = json_decode($test); 74var_dump($obj); 75echo "DECODE: AS ARRAY\n"; 76$arr = json_decode($test, true); 77var_dump($arr); 78 79echo "ENCODE: FROM OBJECT\n"; 80$obj_enc = json_encode($obj, JSON_PARTIAL_OUTPUT_ON_ERROR); 81echo $obj_enc . "\n"; 82echo "ENCODE: FROM ARRAY\n"; 83$arr_enc = json_encode($arr, JSON_PARTIAL_OUTPUT_ON_ERROR); 84echo $arr_enc . "\n"; 85 86echo "DECODE AGAIN: AS OBJECT\n"; 87$obj = json_decode($obj_enc); 88var_dump($obj); 89echo "DECODE AGAIN: AS ARRAY\n"; 90$arr = json_decode($arr_enc, true); 91var_dump($arr); 92 93?> 94--EXPECT-- 95Testing: 96[ 97 "JSON Test Pattern pass1", 98 {"object with 1 member":["array with 1 element"]}, 99 {}, 100 [], 101 -42, 102 true, 103 false, 104 null, 105 { 106 "integer": 1234567890, 107 "real": -9876.543210, 108 "e": 0.123456789e-12, 109 "E": 1.234567890E+34, 110 "": 23456789012E666, 111 "zero": 0, 112 "one": 1, 113 "space": " ", 114 "quote": "\"", 115 "backslash": "\\", 116 "controls": "\b\f\n\r\t", 117 "slash": "/ & \/", 118 "alpha": "abcdefghijklmnopqrstuvwyz", 119 "ALPHA": "ABCDEFGHIJKLMNOPQRSTUVWYZ", 120 "digit": "0123456789", 121 "special": "`1~!@#$%^&*()_+-={':[,]}|;.</>?", 122 "hex": "\u0123\u4567\u89AB\uCDEF\uabcd\uef4A", 123 "true": true, 124 "false": false, 125 "null": null, 126 "array":[ ], 127 "object":{ }, 128 "address": "50 St. James Street", 129 "url": "http://www.JSON.org/", 130 "comment": "// /* <!-- --", 131 "# -- --> */": " ", 132 " s p a c e d " :[1,2 , 3 133 134, 135 1364 , 5 , 6 ,7 ], 137 "compact": [1,2,3,4,5,6,7], 138 "jsontext": "{\"object with 1 member\":[\"array with 1 element\"]}", 139 "quotes": "" \u0022 %22 0x22 034 "", 140 "\/\\\"\uCAFE\uBABE\uAB98\uFCDE\ubcda\uef4A\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',./<>?" 141: "A key can be any string" 142 }, 143 0.5 ,98.6 144, 14599.44 146, 147 1481066 149 150 151,"rosebud"] 152 153DECODE: AS OBJECT 154array(14) { 155 [0]=> 156 string(23) "JSON Test Pattern pass1" 157 [1]=> 158 object(stdClass)#1 (1) { 159 ["object with 1 member"]=> 160 array(1) { 161 [0]=> 162 string(20) "array with 1 element" 163 } 164 } 165 [2]=> 166 object(stdClass)#2 (0) { 167 } 168 [3]=> 169 array(0) { 170 } 171 [4]=> 172 int(-42) 173 [5]=> 174 bool(true) 175 [6]=> 176 bool(false) 177 [7]=> 178 NULL 179 [8]=> 180 object(stdClass)#3 (31) { 181 ["integer"]=> 182 int(1234567890) 183 ["real"]=> 184 float(-9876.54321) 185 ["e"]=> 186 float(1.23456789E-13) 187 ["E"]=> 188 float(1.23456789E+34) 189 [""]=> 190 float(INF) 191 ["zero"]=> 192 int(0) 193 ["one"]=> 194 int(1) 195 ["space"]=> 196 string(1) " " 197 ["quote"]=> 198 string(1) """ 199 ["backslash"]=> 200 string(1) "\" 201 ["controls"]=> 202 string(5) " 203 203 " 204 ["slash"]=> 205 string(5) "/ & /" 206 ["alpha"]=> 207 string(25) "abcdefghijklmnopqrstuvwyz" 208 ["ALPHA"]=> 209 string(25) "ABCDEFGHIJKLMNOPQRSTUVWYZ" 210 ["digit"]=> 211 string(10) "0123456789" 212 ["special"]=> 213 string(31) "`1~!@#$%^&*()_+-={':[,]}|;.</>?" 214 ["hex"]=> 215 string(17) "ģ䕧覫췯ꯍ" 216 ["true"]=> 217 bool(true) 218 ["false"]=> 219 bool(false) 220 ["null"]=> 221 NULL 222 ["array"]=> 223 array(0) { 224 } 225 ["object"]=> 226 object(stdClass)#4 (0) { 227 } 228 ["address"]=> 229 string(19) "50 St. James Street" 230 ["url"]=> 231 string(20) "http://www.JSON.org/" 232 ["comment"]=> 233 string(13) "// /* <!-- --" 234 ["# -- --> */"]=> 235 string(1) " " 236 [" s p a c e d "]=> 237 array(7) { 238 [0]=> 239 int(1) 240 [1]=> 241 int(2) 242 [2]=> 243 int(3) 244 [3]=> 245 int(4) 246 [4]=> 247 int(5) 248 [5]=> 249 int(6) 250 [6]=> 251 int(7) 252 } 253 ["compact"]=> 254 array(7) { 255 [0]=> 256 int(1) 257 [1]=> 258 int(2) 259 [2]=> 260 int(3) 261 [3]=> 262 int(4) 263 [4]=> 264 int(5) 265 [5]=> 266 int(6) 267 [6]=> 268 int(7) 269 } 270 ["jsontext"]=> 271 string(49) "{"object with 1 member":["array with 1 element"]}" 272 ["quotes"]=> 273 string(27) "" " %22 0x22 034 "" 274 ["/\"쫾몾ꮘﳞ볚 275 275 `1~!@#$%^&*()_+-=[]{}|;:',./<>?"]=> 276 string(23) "A key can be any string" 277 } 278 [9]=> 279 float(0.5) 280 [10]=> 281 float(98.6) 282 [11]=> 283 float(99.44) 284 [12]=> 285 int(1066) 286 [13]=> 287 string(7) "rosebud" 288} 289DECODE: AS ARRAY 290array(14) { 291 [0]=> 292 string(23) "JSON Test Pattern pass1" 293 [1]=> 294 array(1) { 295 ["object with 1 member"]=> 296 array(1) { 297 [0]=> 298 string(20) "array with 1 element" 299 } 300 } 301 [2]=> 302 array(0) { 303 } 304 [3]=> 305 array(0) { 306 } 307 [4]=> 308 int(-42) 309 [5]=> 310 bool(true) 311 [6]=> 312 bool(false) 313 [7]=> 314 NULL 315 [8]=> 316 array(31) { 317 ["integer"]=> 318 int(1234567890) 319 ["real"]=> 320 float(-9876.54321) 321 ["e"]=> 322 float(1.23456789E-13) 323 ["E"]=> 324 float(1.23456789E+34) 325 [""]=> 326 float(INF) 327 ["zero"]=> 328 int(0) 329 ["one"]=> 330 int(1) 331 ["space"]=> 332 string(1) " " 333 ["quote"]=> 334 string(1) """ 335 ["backslash"]=> 336 string(1) "\" 337 ["controls"]=> 338 string(5) " 339 339 " 340 ["slash"]=> 341 string(5) "/ & /" 342 ["alpha"]=> 343 string(25) "abcdefghijklmnopqrstuvwyz" 344 ["ALPHA"]=> 345 string(25) "ABCDEFGHIJKLMNOPQRSTUVWYZ" 346 ["digit"]=> 347 string(10) "0123456789" 348 ["special"]=> 349 string(31) "`1~!@#$%^&*()_+-={':[,]}|;.</>?" 350 ["hex"]=> 351 string(17) "ģ䕧覫췯ꯍ" 352 ["true"]=> 353 bool(true) 354 ["false"]=> 355 bool(false) 356 ["null"]=> 357 NULL 358 ["array"]=> 359 array(0) { 360 } 361 ["object"]=> 362 array(0) { 363 } 364 ["address"]=> 365 string(19) "50 St. James Street" 366 ["url"]=> 367 string(20) "http://www.JSON.org/" 368 ["comment"]=> 369 string(13) "// /* <!-- --" 370 ["# -- --> */"]=> 371 string(1) " " 372 [" s p a c e d "]=> 373 array(7) { 374 [0]=> 375 int(1) 376 [1]=> 377 int(2) 378 [2]=> 379 int(3) 380 [3]=> 381 int(4) 382 [4]=> 383 int(5) 384 [5]=> 385 int(6) 386 [6]=> 387 int(7) 388 } 389 ["compact"]=> 390 array(7) { 391 [0]=> 392 int(1) 393 [1]=> 394 int(2) 395 [2]=> 396 int(3) 397 [3]=> 398 int(4) 399 [4]=> 400 int(5) 401 [5]=> 402 int(6) 403 [6]=> 404 int(7) 405 } 406 ["jsontext"]=> 407 string(49) "{"object with 1 member":["array with 1 element"]}" 408 ["quotes"]=> 409 string(27) "" " %22 0x22 034 "" 410 ["/\"쫾몾ꮘﳞ볚 411 411 `1~!@#$%^&*()_+-=[]{}|;:',./<>?"]=> 412 string(23) "A key can be any string" 413 } 414 [9]=> 415 float(0.5) 416 [10]=> 417 float(98.6) 418 [11]=> 419 float(99.44) 420 [12]=> 421 int(1066) 422 [13]=> 423 string(7) "rosebud" 424} 425ENCODE: FROM OBJECT 426["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"] 427ENCODE: FROM ARRAY 428["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"] 429DECODE AGAIN: AS OBJECT 430array(14) { 431 [0]=> 432 string(23) "JSON Test Pattern pass1" 433 [1]=> 434 object(stdClass)#5 (1) { 435 ["object with 1 member"]=> 436 array(1) { 437 [0]=> 438 string(20) "array with 1 element" 439 } 440 } 441 [2]=> 442 object(stdClass)#6 (0) { 443 } 444 [3]=> 445 array(0) { 446 } 447 [4]=> 448 int(-42) 449 [5]=> 450 bool(true) 451 [6]=> 452 bool(false) 453 [7]=> 454 NULL 455 [8]=> 456 object(stdClass)#7 (31) { 457 ["integer"]=> 458 int(1234567890) 459 ["real"]=> 460 float(-9876.54321) 461 ["e"]=> 462 float(1.23456789E-13) 463 ["E"]=> 464 float(1.23456789E+34) 465 [""]=> 466 int(0) 467 ["zero"]=> 468 int(0) 469 ["one"]=> 470 int(1) 471 ["space"]=> 472 string(1) " " 473 ["quote"]=> 474 string(1) """ 475 ["backslash"]=> 476 string(1) "\" 477 ["controls"]=> 478 string(5) " 479 479 " 480 ["slash"]=> 481 string(5) "/ & /" 482 ["alpha"]=> 483 string(25) "abcdefghijklmnopqrstuvwyz" 484 ["ALPHA"]=> 485 string(25) "ABCDEFGHIJKLMNOPQRSTUVWYZ" 486 ["digit"]=> 487 string(10) "0123456789" 488 ["special"]=> 489 string(31) "`1~!@#$%^&*()_+-={':[,]}|;.</>?" 490 ["hex"]=> 491 string(17) "ģ䕧覫췯ꯍ" 492 ["true"]=> 493 bool(true) 494 ["false"]=> 495 bool(false) 496 ["null"]=> 497 NULL 498 ["array"]=> 499 array(0) { 500 } 501 ["object"]=> 502 object(stdClass)#8 (0) { 503 } 504 ["address"]=> 505 string(19) "50 St. James Street" 506 ["url"]=> 507 string(20) "http://www.JSON.org/" 508 ["comment"]=> 509 string(13) "// /* <!-- --" 510 ["# -- --> */"]=> 511 string(1) " " 512 [" s p a c e d "]=> 513 array(7) { 514 [0]=> 515 int(1) 516 [1]=> 517 int(2) 518 [2]=> 519 int(3) 520 [3]=> 521 int(4) 522 [4]=> 523 int(5) 524 [5]=> 525 int(6) 526 [6]=> 527 int(7) 528 } 529 ["compact"]=> 530 array(7) { 531 [0]=> 532 int(1) 533 [1]=> 534 int(2) 535 [2]=> 536 int(3) 537 [3]=> 538 int(4) 539 [4]=> 540 int(5) 541 [5]=> 542 int(6) 543 [6]=> 544 int(7) 545 } 546 ["jsontext"]=> 547 string(49) "{"object with 1 member":["array with 1 element"]}" 548 ["quotes"]=> 549 string(27) "" " %22 0x22 034 "" 550 ["/\"쫾몾ꮘﳞ볚 551 551 `1~!@#$%^&*()_+-=[]{}|;:',./<>?"]=> 552 string(23) "A key can be any string" 553 } 554 [9]=> 555 float(0.5) 556 [10]=> 557 float(98.6) 558 [11]=> 559 float(99.44) 560 [12]=> 561 int(1066) 562 [13]=> 563 string(7) "rosebud" 564} 565DECODE AGAIN: AS ARRAY 566array(14) { 567 [0]=> 568 string(23) "JSON Test Pattern pass1" 569 [1]=> 570 array(1) { 571 ["object with 1 member"]=> 572 array(1) { 573 [0]=> 574 string(20) "array with 1 element" 575 } 576 } 577 [2]=> 578 array(0) { 579 } 580 [3]=> 581 array(0) { 582 } 583 [4]=> 584 int(-42) 585 [5]=> 586 bool(true) 587 [6]=> 588 bool(false) 589 [7]=> 590 NULL 591 [8]=> 592 array(31) { 593 ["integer"]=> 594 int(1234567890) 595 ["real"]=> 596 float(-9876.54321) 597 ["e"]=> 598 float(1.23456789E-13) 599 ["E"]=> 600 float(1.23456789E+34) 601 [""]=> 602 int(0) 603 ["zero"]=> 604 int(0) 605 ["one"]=> 606 int(1) 607 ["space"]=> 608 string(1) " " 609 ["quote"]=> 610 string(1) """ 611 ["backslash"]=> 612 string(1) "\" 613 ["controls"]=> 614 string(5) " 615 615 " 616 ["slash"]=> 617 string(5) "/ & /" 618 ["alpha"]=> 619 string(25) "abcdefghijklmnopqrstuvwyz" 620 ["ALPHA"]=> 621 string(25) "ABCDEFGHIJKLMNOPQRSTUVWYZ" 622 ["digit"]=> 623 string(10) "0123456789" 624 ["special"]=> 625 string(31) "`1~!@#$%^&*()_+-={':[,]}|;.</>?" 626 ["hex"]=> 627 string(17) "ģ䕧覫췯ꯍ" 628 ["true"]=> 629 bool(true) 630 ["false"]=> 631 bool(false) 632 ["null"]=> 633 NULL 634 ["array"]=> 635 array(0) { 636 } 637 ["object"]=> 638 array(0) { 639 } 640 ["address"]=> 641 string(19) "50 St. James Street" 642 ["url"]=> 643 string(20) "http://www.JSON.org/" 644 ["comment"]=> 645 string(13) "// /* <!-- --" 646 ["# -- --> */"]=> 647 string(1) " " 648 [" s p a c e d "]=> 649 array(7) { 650 [0]=> 651 int(1) 652 [1]=> 653 int(2) 654 [2]=> 655 int(3) 656 [3]=> 657 int(4) 658 [4]=> 659 int(5) 660 [5]=> 661 int(6) 662 [6]=> 663 int(7) 664 } 665 ["compact"]=> 666 array(7) { 667 [0]=> 668 int(1) 669 [1]=> 670 int(2) 671 [2]=> 672 int(3) 673 [3]=> 674 int(4) 675 [4]=> 676 int(5) 677 [5]=> 678 int(6) 679 [6]=> 680 int(7) 681 } 682 ["jsontext"]=> 683 string(49) "{"object with 1 member":["array with 1 element"]}" 684 ["quotes"]=> 685 string(27) "" " %22 0x22 034 "" 686 ["/\"쫾몾ꮘﳞ볚 687 687 `1~!@#$%^&*()_+-=[]{}|;:',./<>?"]=> 688 string(23) "A key can be any string" 689 } 690 [9]=> 691 float(0.5) 692 [10]=> 693 float(98.6) 694 [11]=> 695 float(99.44) 696 [12]=> 697 int(1066) 698 [13]=> 699 string(7) "rosebud" 700} 701