xref: /PHP-8.3/ext/json/tests/pass002.phpt (revision 32a1ebbd)
1--TEST--
2JSON (http://www.crockford.com/JSON/JSON_checker/test/pass2.json)
3--FILE--
4<?php
5
6$test = '[[[[[[[[[[[[[[[[[[["Not too deep"]]]]]]]]]]]]]]]]]]]';
7echo 'Testing: ' . $test . "\n";
8echo "DECODE: AS OBJECT\n";
9$obj = json_decode($test);
10var_dump($obj);
11echo "DECODE: AS ARRAY\n";
12$arr = json_decode($test, true);
13var_dump($arr);
14
15echo "ENCODE: FROM OBJECT\n";
16$obj_enc = json_encode($obj);
17echo $obj_enc . "\n";
18echo "ENCODE: FROM ARRAY\n";
19$arr_enc = json_encode($arr);
20echo $arr_enc . "\n";
21
22echo "DECODE AGAIN: AS OBJECT\n";
23$obj = json_decode($obj_enc);
24var_dump($obj);
25echo "DECODE AGAIN: AS ARRAY\n";
26$arr = json_decode($arr_enc, true);
27var_dump($arr);
28
29?>
30--EXPECT--
31Testing: [[[[[[[[[[[[[[[[[[["Not too deep"]]]]]]]]]]]]]]]]]]]
32DECODE: AS OBJECT
33array(1) {
34  [0]=>
35  array(1) {
36    [0]=>
37    array(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                                      string(12) "Not too deep"
72                                    }
73                                  }
74                                }
75                              }
76                            }
77                          }
78                        }
79                      }
80                    }
81                  }
82                }
83              }
84            }
85          }
86        }
87      }
88    }
89  }
90}
91DECODE: AS ARRAY
92array(1) {
93  [0]=>
94  array(1) {
95    [0]=>
96    array(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                                      string(12) "Not too deep"
131                                    }
132                                  }
133                                }
134                              }
135                            }
136                          }
137                        }
138                      }
139                    }
140                  }
141                }
142              }
143            }
144          }
145        }
146      }
147    }
148  }
149}
150ENCODE: FROM OBJECT
151[[[[[[[[[[[[[[[[[[["Not too deep"]]]]]]]]]]]]]]]]]]]
152ENCODE: FROM ARRAY
153[[[[[[[[[[[[[[[[[[["Not too deep"]]]]]]]]]]]]]]]]]]]
154DECODE AGAIN: AS OBJECT
155array(1) {
156  [0]=>
157  array(1) {
158    [0]=>
159    array(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                                      string(12) "Not too deep"
194                                    }
195                                  }
196                                }
197                              }
198                            }
199                          }
200                        }
201                      }
202                    }
203                  }
204                }
205              }
206            }
207          }
208        }
209      }
210    }
211  }
212}
213DECODE AGAIN: AS ARRAY
214array(1) {
215  [0]=>
216  array(1) {
217    [0]=>
218    array(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                                      string(12) "Not too deep"
253                                    }
254                                  }
255                                }
256                              }
257                            }
258                          }
259                        }
260                      }
261                    }
262                  }
263                }
264              }
265            }
266          }
267        }
268      }
269    }
270  }
271}
272