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