xref: /PHP-5.3/ext/json/tests/pass002.phpt (revision efc6ff0c)
1--TEST--
2JSON (http://www.crockford.com/JSON/JSON_checker/test/pass2.json)
3--SKIPIF--
4<?php
5  if (!extension_loaded('json')) die('skip: json extension not available');
6?>
7--FILE--
8<?php
9
10$test = '[[[[[[[[[[[[[[[[[[["Not too deep"]]]]]]]]]]]]]]]]]]]';
11echo 'Testing: ' . $test . "\n";
12echo "DECODE: AS OBJECT\n";
13$obj = json_decode($test);
14var_dump($obj);
15echo "DECODE: AS ARRAY\n";
16$arr = json_decode($test, true);
17var_dump($arr);
18
19echo "ENCODE: FROM OBJECT\n";
20$obj_enc = json_encode($obj);
21echo $obj_enc . "\n";
22echo "ENCODE: FROM ARRAY\n";
23$arr_enc = json_encode($arr);
24echo $arr_enc . "\n";
25
26echo "DECODE AGAIN: AS OBJECT\n";
27$obj = json_decode($obj_enc);
28var_dump($obj);
29echo "DECODE AGAIN: AS ARRAY\n";
30$arr = json_decode($arr_enc, true);
31var_dump($arr);
32
33?>
34--EXPECT--
35Testing: [[[[[[[[[[[[[[[[[[["Not too deep"]]]]]]]]]]]]]]]]]]]
36DECODE: AS OBJECT
37array(1) {
38  [0]=>
39  array(1) {
40    [0]=>
41    array(1) {
42      [0]=>
43      array(1) {
44        [0]=>
45        array(1) {
46          [0]=>
47          array(1) {
48            [0]=>
49            array(1) {
50              [0]=>
51              array(1) {
52                [0]=>
53                array(1) {
54                  [0]=>
55                  array(1) {
56                    [0]=>
57                    array(1) {
58                      [0]=>
59                      array(1) {
60                        [0]=>
61                        array(1) {
62                          [0]=>
63                          array(1) {
64                            [0]=>
65                            array(1) {
66                              [0]=>
67                              array(1) {
68                                [0]=>
69                                array(1) {
70                                  [0]=>
71                                  array(1) {
72                                    [0]=>
73                                    array(1) {
74                                      [0]=>
75                                      string(12) "Not too deep"
76                                    }
77                                  }
78                                }
79                              }
80                            }
81                          }
82                        }
83                      }
84                    }
85                  }
86                }
87              }
88            }
89          }
90        }
91      }
92    }
93  }
94}
95DECODE: AS ARRAY
96array(1) {
97  [0]=>
98  array(1) {
99    [0]=>
100    array(1) {
101      [0]=>
102      array(1) {
103        [0]=>
104        array(1) {
105          [0]=>
106          array(1) {
107            [0]=>
108            array(1) {
109              [0]=>
110              array(1) {
111                [0]=>
112                array(1) {
113                  [0]=>
114                  array(1) {
115                    [0]=>
116                    array(1) {
117                      [0]=>
118                      array(1) {
119                        [0]=>
120                        array(1) {
121                          [0]=>
122                          array(1) {
123                            [0]=>
124                            array(1) {
125                              [0]=>
126                              array(1) {
127                                [0]=>
128                                array(1) {
129                                  [0]=>
130                                  array(1) {
131                                    [0]=>
132                                    array(1) {
133                                      [0]=>
134                                      string(12) "Not too deep"
135                                    }
136                                  }
137                                }
138                              }
139                            }
140                          }
141                        }
142                      }
143                    }
144                  }
145                }
146              }
147            }
148          }
149        }
150      }
151    }
152  }
153}
154ENCODE: FROM OBJECT
155[[[[[[[[[[[[[[[[[[["Not too deep"]]]]]]]]]]]]]]]]]]]
156ENCODE: FROM ARRAY
157[[[[[[[[[[[[[[[[[[["Not too deep"]]]]]]]]]]]]]]]]]]]
158DECODE AGAIN: AS OBJECT
159array(1) {
160  [0]=>
161  array(1) {
162    [0]=>
163    array(1) {
164      [0]=>
165      array(1) {
166        [0]=>
167        array(1) {
168          [0]=>
169          array(1) {
170            [0]=>
171            array(1) {
172              [0]=>
173              array(1) {
174                [0]=>
175                array(1) {
176                  [0]=>
177                  array(1) {
178                    [0]=>
179                    array(1) {
180                      [0]=>
181                      array(1) {
182                        [0]=>
183                        array(1) {
184                          [0]=>
185                          array(1) {
186                            [0]=>
187                            array(1) {
188                              [0]=>
189                              array(1) {
190                                [0]=>
191                                array(1) {
192                                  [0]=>
193                                  array(1) {
194                                    [0]=>
195                                    array(1) {
196                                      [0]=>
197                                      string(12) "Not too deep"
198                                    }
199                                  }
200                                }
201                              }
202                            }
203                          }
204                        }
205                      }
206                    }
207                  }
208                }
209              }
210            }
211          }
212        }
213      }
214    }
215  }
216}
217DECODE AGAIN: AS ARRAY
218array(1) {
219  [0]=>
220  array(1) {
221    [0]=>
222    array(1) {
223      [0]=>
224      array(1) {
225        [0]=>
226        array(1) {
227          [0]=>
228          array(1) {
229            [0]=>
230            array(1) {
231              [0]=>
232              array(1) {
233                [0]=>
234                array(1) {
235                  [0]=>
236                  array(1) {
237                    [0]=>
238                    array(1) {
239                      [0]=>
240                      array(1) {
241                        [0]=>
242                        array(1) {
243                          [0]=>
244                          array(1) {
245                            [0]=>
246                            array(1) {
247                              [0]=>
248                              array(1) {
249                                [0]=>
250                                array(1) {
251                                  [0]=>
252                                  array(1) {
253                                    [0]=>
254                                    array(1) {
255                                      [0]=>
256                                      string(12) "Not too deep"
257                                    }
258                                  }
259                                }
260                              }
261                            }
262                          }
263                        }
264                      }
265                    }
266                  }
267                }
268              }
269            }
270          }
271        }
272      }
273    }
274  }
275}
276