xref: /PHP-7.1/ext/json/tests/pass003.phpt (revision 7af945e2)
1--TEST--
2JSON (http://www.crockford.com/JSON/JSON_checker/test/pass3.json)
3--SKIPIF--
4<?php if (!extension_loaded("json")) print "skip"; ?>
5--FILE--
6<?php
7
8$test = '
9{
10    "JSON Test Pattern pass3": {
11        "The outermost value": "must be an object or array.",
12        "In this test": "It is an object."
13    }
14}
15';
16
17echo 'Testing: ' . $test . "\n";
18echo "DECODE: AS OBJECT\n";
19$obj = json_decode($test);
20var_dump($obj);
21echo "DECODE: AS ARRAY\n";
22$arr = json_decode($test, true);
23var_dump($arr);
24
25echo "ENCODE: FROM OBJECT\n";
26$obj_enc = json_encode($obj);
27echo $obj_enc . "\n";
28echo "ENCODE: FROM ARRAY\n";
29$arr_enc = json_encode($arr);
30echo $arr_enc . "\n";
31
32echo "DECODE AGAIN: AS OBJECT\n";
33$obj = json_decode($obj_enc);
34var_dump($obj);
35echo "DECODE AGAIN: AS ARRAY\n";
36$arr = json_decode($arr_enc, true);
37var_dump($arr);
38
39?>
40--EXPECTF--
41Testing:
42{
43    "JSON Test Pattern pass3": {
44        "The outermost value": "must be an object or array.",
45        "In this test": "It is an object."
46    }
47}
48
49DECODE: AS OBJECT
50object(stdClass)#%d (1) {
51  ["JSON Test Pattern pass3"]=>
52  object(stdClass)#%d (2) {
53    ["The outermost value"]=>
54    string(27) "must be an object or array."
55    ["In this test"]=>
56    string(16) "It is an object."
57  }
58}
59DECODE: AS ARRAY
60array(1) {
61  ["JSON Test Pattern pass3"]=>
62  array(2) {
63    ["The outermost value"]=>
64    string(27) "must be an object or array."
65    ["In this test"]=>
66    string(16) "It is an object."
67  }
68}
69ENCODE: FROM OBJECT
70{"JSON Test Pattern pass3":{"The outermost value":"must be an object or array.","In this test":"It is an object."}}
71ENCODE: FROM ARRAY
72{"JSON Test Pattern pass3":{"The outermost value":"must be an object or array.","In this test":"It is an object."}}
73DECODE AGAIN: AS OBJECT
74object(stdClass)#%d (1) {
75  ["JSON Test Pattern pass3"]=>
76  object(stdClass)#%d (2) {
77    ["The outermost value"]=>
78    string(27) "must be an object or array."
79    ["In this test"]=>
80    string(16) "It is an object."
81  }
82}
83DECODE AGAIN: AS ARRAY
84array(1) {
85  ["JSON Test Pattern pass3"]=>
86  array(2) {
87    ["The outermost value"]=>
88    string(27) "must be an object or array."
89    ["In this test"]=>
90    string(16) "It is an object."
91  }
92}
93