xref: /sqlite-3.40.0/test/json102.test (revision e229ca03)
1852944ebSdrh# 2015-08-12
2852944ebSdrh#
3852944ebSdrh# The author disclaims copyright to this source code.  In place of
4852944ebSdrh# a legal notice, here is a blessing:
5852944ebSdrh#
6852944ebSdrh#    May you do good and not evil.
7852944ebSdrh#    May you find forgiveness for yourself and forgive others.
8852944ebSdrh#    May you share freely, never taking more than you give.
9852944ebSdrh#
10852944ebSdrh#***********************************************************************
11852944ebSdrh# This file implements tests for JSON SQL functions extension to the
12852944ebSdrh# SQLite library.
13852944ebSdrh#
14852944ebSdrh# This file contains tests automatically generated from the json1
15852944ebSdrh# documentation.
16852944ebSdrh#
17852944ebSdrh
18852944ebSdrhset testdir [file dirname $argv0]
19852944ebSdrhsource $testdir/tester.tcl
20852944ebSdrh
21852944ebSdrhdo_execsql_test json102-100 {
22e98b6fabSdrh  SELECT json_object('ex','[52,3.14159]');
23e98b6fabSdrh} {{{"ex":"[52,3.14159]"}}}
24e98b6fabSdrhdo_execsql_test json102-110 {
25e98b6fabSdrh  SELECT json_object('ex',json('[52,3.14159]'));
26e98b6fabSdrh} {{{"ex":[52,3.14159]}}}
27e98b6fabSdrhdo_execsql_test json102-120 {
28e98b6fabSdrh  SELECT json_object('ex',json_array(52,3.14159));
29e98b6fabSdrh} {{{"ex":[52,3.14159]}}}
30e98b6fabSdrhdo_execsql_test json102-130 {
3112b3b895Sdrh  SELECT json(' { "this" : "is", "a": [ "test" ] } ');
3212b3b895Sdrh} {{{"this":"is","a":["test"]}}}
33e98b6fabSdrhdo_execsql_test json102-140 {
34852944ebSdrh  SELECT json_array(1,2,'3',4);
35852944ebSdrh} {{[1,2,"3",4]}}
36e98b6fabSdrhdo_execsql_test json102-150 {
37852944ebSdrh  SELECT json_array('[1,2]');
38852944ebSdrh} {{["[1,2]"]}}
39e98b6fabSdrhdo_execsql_test json102-160 {
4012b3b895Sdrh  SELECT json_array(json_array(1,2));
4112b3b895Sdrh} {{[[1,2]]}}
42e98b6fabSdrhdo_execsql_test json102-170 {
43852944ebSdrh  SELECT json_array(1,null,'3','[4,5]','{"six":7.7}');
44852944ebSdrh} {{[1,null,"3","[4,5]","{\"six\":7.7}"]}}
45e98b6fabSdrhdo_execsql_test json102-180 {
4612b3b895Sdrh  SELECT json_array(1,null,'3',json('[4,5]'),json('{"six":7.7}'));
4712b3b895Sdrh} {{[1,null,"3",[4,5],{"six":7.7}]}}
48e98b6fabSdrhdo_execsql_test json102-190 {
49852944ebSdrh  SELECT json_array_length('[1,2,3,4]');
50852944ebSdrh} {{4}}
51e98b6fabSdrhdo_execsql_test json102-200 {
52e98b6fabSdrh  SELECT json_array_length('[1,2,3,4]', '$');
53e98b6fabSdrh} {{4}}
54e98b6fabSdrhdo_execsql_test json102-210 {
55e98b6fabSdrh  SELECT json_array_length('[1,2,3,4]', '$[2]');
56e98b6fabSdrh} {{0}}
57e98b6fabSdrhdo_execsql_test json102-220 {
58852944ebSdrh  SELECT json_array_length('{"one":[1,2,3]}');
59852944ebSdrh} {{0}}
60e98b6fabSdrhdo_execsql_test json102-230 {
61852944ebSdrh  SELECT json_array_length('{"one":[1,2,3]}', '$.one');
62852944ebSdrh} {{3}}
6312b3b895Sdrhdo_execsql_test json102-240 {
64e98b6fabSdrh  SELECT json_array_length('{"one":[1,2,3]}', '$.two');
65852944ebSdrh} {{}}
6612b3b895Sdrhdo_execsql_test json102-250 {
67e98b6fabSdrh  SELECT json_extract('{"a":2,"c":[4,5,{"f":7}]}', '$');
68e98b6fabSdrh} {{{"a":2,"c":[4,5,{"f":7}]}}}
69e98b6fabSdrhdo_execsql_test json102-260 {
70e98b6fabSdrh  SELECT json_extract('{"a":2,"c":[4,5,{"f":7}]}', '$.c');
71e98b6fabSdrh} {{[4,5,{"f":7}]}}
72e98b6fabSdrhdo_execsql_test json102-270 {
73e98b6fabSdrh  SELECT json_extract('{"a":2,"c":[4,5,{"f":7}]}', '$.c[2]');
74e98b6fabSdrh} {{{"f":7}}}
75e98b6fabSdrhdo_execsql_test json102-280 {
76e98b6fabSdrh  SELECT json_extract('{"a":2,"c":[4,5,{"f":7}]}', '$.c[2].f');
77e98b6fabSdrh} {{7}}
78e98b6fabSdrhdo_execsql_test json102-290 {
79e98b6fabSdrh  SELECT json_extract('{"a":2,"c":[4,5],"f":7}','$.c','$.a');
80e98b6fabSdrh} {{[[4,5],2]}}
81e98b6fabSdrhdo_execsql_test json102-300 {
82e98b6fabSdrh  SELECT json_extract('{"a":2,"c":[4,5,{"f":7}]}', '$.x');
83e98b6fabSdrh} {{}}
84e98b6fabSdrhdo_execsql_test json102-310 {
85e98b6fabSdrh  SELECT json_extract('{"a":2,"c":[4,5,{"f":7}]}', '$.x', '$.a');
86e98b6fabSdrh} {{[null,2]}}
87e98b6fabSdrhdo_execsql_test json102-320 {
88852944ebSdrh  SELECT json_insert('{"a":2,"c":4}', '$.a', 99);
89852944ebSdrh} {{{"a":2,"c":4}}}
90e98b6fabSdrhdo_execsql_test json102-330 {
91852944ebSdrh  SELECT json_insert('{"a":2,"c":4}', '$.e', 99);
92852944ebSdrh} {{{"a":2,"c":4,"e":99}}}
93e98b6fabSdrhdo_execsql_test json102-340 {
94852944ebSdrh  SELECT json_replace('{"a":2,"c":4}', '$.a', 99);
95852944ebSdrh} {{{"a":99,"c":4}}}
96e98b6fabSdrhdo_execsql_test json102-350 {
97852944ebSdrh  SELECT json_replace('{"a":2,"c":4}', '$.e', 99);
98852944ebSdrh} {{{"a":2,"c":4}}}
99e98b6fabSdrhdo_execsql_test json102-360 {
100852944ebSdrh  SELECT json_set('{"a":2,"c":4}', '$.a', 99);
101852944ebSdrh} {{{"a":99,"c":4}}}
102e98b6fabSdrhdo_execsql_test json102-370 {
103852944ebSdrh  SELECT json_set('{"a":2,"c":4}', '$.e', 99);
104852944ebSdrh} {{{"a":2,"c":4,"e":99}}}
105e98b6fabSdrhdo_execsql_test json102-380 {
10612b3b895Sdrh  SELECT json_set('{"a":2,"c":4}', '$.c', '[97,96]');
10712b3b895Sdrh} {{{"a":2,"c":"[97,96]"}}}
108e98b6fabSdrhdo_execsql_test json102-390 {
10912b3b895Sdrh  SELECT json_set('{"a":2,"c":4}', '$.c', json('[97,96]'));
11012b3b895Sdrh} {{{"a":2,"c":[97,96]}}}
111e98b6fabSdrhdo_execsql_test json102-400 {
11212b3b895Sdrh  SELECT json_set('{"a":2,"c":4}', '$.c', json_array(97,96));
11312b3b895Sdrh} {{{"a":2,"c":[97,96]}}}
114e98b6fabSdrhdo_execsql_test json102-410 {
115852944ebSdrh  SELECT json_object('a',2,'c',4);
116852944ebSdrh} {{{"a":2,"c":4}}}
117e98b6fabSdrhdo_execsql_test json102-420 {
118852944ebSdrh  SELECT json_object('a',2,'c','{e:5}');
119852944ebSdrh} {{{"a":2,"c":"{e:5}"}}}
120e98b6fabSdrhdo_execsql_test json102-430 {
12112b3b895Sdrh  SELECT json_object('a',2,'c',json_object('e',5));
12212b3b895Sdrh} {{{"a":2,"c":{"e":5}}}}
123e98b6fabSdrhdo_execsql_test json102-440 {
124852944ebSdrh  SELECT json_remove('[0,1,2,3,4]','$[2]');
125852944ebSdrh} {{[0,1,3,4]}}
126e98b6fabSdrhdo_execsql_test json102-450 {
127852944ebSdrh  SELECT json_remove('[0,1,2,3,4]','$[2]','$[0]');
128852944ebSdrh} {{[1,3,4]}}
129e98b6fabSdrhdo_execsql_test json102-460 {
130852944ebSdrh  SELECT json_remove('[0,1,2,3,4]','$[0]','$[2]');
131852944ebSdrh} {{[1,2,4]}}
132e98b6fabSdrhdo_execsql_test json102-470 {
133852944ebSdrh  SELECT json_remove('{"x":25,"y":42}');
134852944ebSdrh} {{{"x":25,"y":42}}}
135e98b6fabSdrhdo_execsql_test json102-480 {
136852944ebSdrh  SELECT json_remove('{"x":25,"y":42}','$.z');
137852944ebSdrh} {{{"x":25,"y":42}}}
138e98b6fabSdrhdo_execsql_test json102-490 {
139852944ebSdrh  SELECT json_remove('{"x":25,"y":42}','$.y');
140852944ebSdrh} {{{"x":25}}}
141e98b6fabSdrhdo_execsql_test json102-500 {
142852944ebSdrh  SELECT json_remove('{"x":25,"y":42}','$');
143852944ebSdrh} {{}}
144e98b6fabSdrhdo_execsql_test json102-510 {
145852944ebSdrh  SELECT json_type('{"a":[2,3.5,true,false,null,"x"]}');
146852944ebSdrh} {{object}}
147e98b6fabSdrhdo_execsql_test json102-520 {
148852944ebSdrh  SELECT json_type('{"a":[2,3.5,true,false,null,"x"]}','$');
149852944ebSdrh} {{object}}
150e98b6fabSdrhdo_execsql_test json102-530 {
151852944ebSdrh  SELECT json_type('{"a":[2,3.5,true,false,null,"x"]}','$.a');
152852944ebSdrh} {{array}}
153e98b6fabSdrhdo_execsql_test json102-540 {
154852944ebSdrh  SELECT json_type('{"a":[2,3.5,true,false,null,"x"]}','$.a[0]');
155852944ebSdrh} {{integer}}
156e98b6fabSdrhdo_execsql_test json102-550 {
157852944ebSdrh  SELECT json_type('{"a":[2,3.5,true,false,null,"x"]}','$.a[1]');
158852944ebSdrh} {{real}}
159e98b6fabSdrhdo_execsql_test json102-560 {
160852944ebSdrh  SELECT json_type('{"a":[2,3.5,true,false,null,"x"]}','$.a[2]');
161852944ebSdrh} {{true}}
162e98b6fabSdrhdo_execsql_test json102-570 {
163852944ebSdrh  SELECT json_type('{"a":[2,3.5,true,false,null,"x"]}','$.a[3]');
164852944ebSdrh} {{false}}
165e98b6fabSdrhdo_execsql_test json102-580 {
166852944ebSdrh  SELECT json_type('{"a":[2,3.5,true,false,null,"x"]}','$.a[4]');
167852944ebSdrh} {{null}}
168e98b6fabSdrhdo_execsql_test json102-590 {
169852944ebSdrh  SELECT json_type('{"a":[2,3.5,true,false,null,"x"]}','$.a[5]');
170852944ebSdrh} {{text}}
171e98b6fabSdrhdo_execsql_test json102-600 {
172852944ebSdrh  SELECT json_type('{"a":[2,3.5,true,false,null,"x"]}','$.a[6]');
173852944ebSdrh} {{}}
174e98b6fabSdrhdo_execsql_test json102-610 {
17512b3b895Sdrh  SELECT json_valid(char(123)||'"x":35'||char(125));
176852944ebSdrh} {{1}}
177e98b6fabSdrhdo_execsql_test json102-620 {
17812b3b895Sdrh  SELECT json_valid(char(123)||'"x":35');
179852944ebSdrh} {{0}}
180852944ebSdrh
181e6f5278cSdrhifcapable vtab {
18212b3b895Sdrhdo_execsql_test json102-1000 {
183852944ebSdrh  CREATE TABLE user(name,phone);
184852944ebSdrh  INSERT INTO user(name,phone) VALUES
185852944ebSdrh     ('Alice','["919-555-2345","804-555-3621"]'),
186852944ebSdrh     ('Bob','["201-555-8872"]'),
187852944ebSdrh     ('Cindy','["704-555-9983"]'),
188852944ebSdrh     ('Dave','["336-555-8421","704-555-4321","803-911-4421"]');
189852944ebSdrh  SELECT DISTINCT user.name
190852944ebSdrh    FROM user, json_each(user.phone)
191852944ebSdrh   WHERE json_each.value LIKE '704-%'
192852944ebSdrh   ORDER BY 1;
193852944ebSdrh} {Cindy Dave}
194852944ebSdrh
19512b3b895Sdrhdo_execsql_test json102-1010 {
196852944ebSdrh  UPDATE user
197852944ebSdrh     SET phone=json_extract(phone,'$[0]')
198852944ebSdrh   WHERE json_array_length(phone)<2;
199852944ebSdrh  SELECT name, substr(phone,1,5) FROM user ORDER BY name;
200852944ebSdrh} {Alice {["919} Bob 201-5 Cindy 704-5 Dave {["336}}
20112b3b895Sdrhdo_execsql_test json102-1011 {
202852944ebSdrh  SELECT name FROM user WHERE phone LIKE '704-%'
203852944ebSdrh  UNION
204852944ebSdrh  SELECT user.name
205852944ebSdrh    FROM user, json_each(user.phone)
206852944ebSdrh   WHERE json_valid(user.phone)
207852944ebSdrh     AND json_each.value LIKE '704-%';
208852944ebSdrh} {Cindy Dave}
209852944ebSdrh
21012b3b895Sdrhdo_execsql_test json102-1100 {
211852944ebSdrh  CREATE TABLE big(json JSON);
212852944ebSdrh  INSERT INTO big(json) VALUES('{
213852944ebSdrh    "id":123,
214852944ebSdrh    "stuff":[1,2,3,4],
215852944ebSdrh    "partlist":[
216852944ebSdrh       {"uuid":"bb108722-572e-11e5-9320-7f3b63a4ca74"},
217852944ebSdrh       {"uuid":"c690dc14-572e-11e5-95f9-dfc8861fd535"},
218852944ebSdrh       {"subassembly":[
219852944ebSdrh          {"uuid":"6fa5181e-5721-11e5-a04e-57f3d7b32808"}
220852944ebSdrh       ]}
221852944ebSdrh    ]
222852944ebSdrh  }');
223852944ebSdrh  INSERT INTO big(json) VALUES('{
224852944ebSdrh    "id":456,
225852944ebSdrh    "stuff":["hello","world","xyzzy"],
226852944ebSdrh    "partlist":[
227852944ebSdrh       {"uuid":false},
228852944ebSdrh       {"uuid":"c690dc14-572e-11e5-95f9-dfc8861fd535"}
229852944ebSdrh    ]
230852944ebSdrh  }');
231852944ebSdrh} {}
232852944ebSdrhset correct_answer [list \
233852944ebSdrh    1 {$.id} 123 \
234852944ebSdrh    1 {$.stuff[0]} 1 \
235852944ebSdrh    1 {$.stuff[1]} 2 \
236852944ebSdrh    1 {$.stuff[2]} 3 \
237852944ebSdrh    1 {$.stuff[3]} 4 \
238852944ebSdrh    1 {$.partlist[0].uuid} bb108722-572e-11e5-9320-7f3b63a4ca74 \
239852944ebSdrh    1 {$.partlist[1].uuid} c690dc14-572e-11e5-95f9-dfc8861fd535 \
240852944ebSdrh    1 {$.partlist[2].subassembly[0].uuid} 6fa5181e-5721-11e5-a04e-57f3d7b32808 \
241852944ebSdrh    2 {$.id} 456 \
242852944ebSdrh    2 {$.stuff[0]} hello \
243852944ebSdrh    2 {$.stuff[1]} world \
244852944ebSdrh    2 {$.stuff[2]} xyzzy \
245852944ebSdrh    2 {$.partlist[0].uuid} 0 \
246852944ebSdrh    2 {$.partlist[1].uuid} c690dc14-572e-11e5-95f9-dfc8861fd535]
24712b3b895Sdrhdo_execsql_test json102-1110 {
248852944ebSdrh  SELECT big.rowid, fullkey, value
249852944ebSdrh    FROM big, json_tree(big.json)
250852944ebSdrh   WHERE json_tree.type NOT IN ('object','array')
251852944ebSdrh   ORDER BY +big.rowid, +json_tree.id
252852944ebSdrh} $correct_answer
25312b3b895Sdrhdo_execsql_test json102-1120 {
254852944ebSdrh  SELECT big.rowid, fullkey, atom
255852944ebSdrh    FROM big, json_tree(big.json)
256852944ebSdrh   WHERE atom IS NOT NULL
257852944ebSdrh   ORDER BY +big.rowid, +json_tree.id
258852944ebSdrh} $correct_answer
259852944ebSdrh
26012b3b895Sdrhdo_execsql_test json102-1130 {
261852944ebSdrh  SELECT DISTINCT json_extract(big.json,'$.id')
262852944ebSdrh    FROM big, json_tree(big.json,'$.partlist')
263852944ebSdrh   WHERE json_tree.key='uuid'
264852944ebSdrh     AND json_tree.value='6fa5181e-5721-11e5-a04e-57f3d7b32808';
265852944ebSdrh} {123}
26612b3b895Sdrhdo_execsql_test json102-1131 {
267852944ebSdrh  SELECT DISTINCT json_extract(big.json,'$.id')
268852944ebSdrh    FROM big, json_tree(big.json,'$')
269852944ebSdrh   WHERE json_tree.key='uuid'
270852944ebSdrh     AND json_tree.value='6fa5181e-5721-11e5-a04e-57f3d7b32808';
271852944ebSdrh} {123}
27212b3b895Sdrhdo_execsql_test json102-1132 {
273852944ebSdrh  SELECT DISTINCT json_extract(big.json,'$.id')
274852944ebSdrh    FROM big, json_tree(big.json)
275852944ebSdrh   WHERE json_tree.key='uuid'
276852944ebSdrh     AND json_tree.value='6fa5181e-5721-11e5-a04e-57f3d7b32808';
277852944ebSdrh} {123}
278e6f5278cSdrh} ;# end ifcapable vtab
279852944ebSdrh
2802e8f5517Sdan#-------------------------------------------------------------------------
2812e8f5517Sdan# Test that json_valid() correctly identifies non-ascii range
2822e8f5517Sdan# characters as non-whitespace.
2832e8f5517Sdan#
2842e8f5517Sdando_execsql_test json102-1201 { SELECT json_valid(char(32)  || '"xyz"') } 1
2852e8f5517Sdando_execsql_test json102-1202 { SELECT json_valid(char(200) || '"xyz"') } 0
2862e8f5517Sdan
2874977ccf1Sdrh# Off-by-one error in jsonAppendString()
2884977ccf1Sdrh#
2894977ccf1Sdrhfor {set i 0} {$i<100} {incr i} {
2904977ccf1Sdrh  set str abcdef[string repeat \" [expr {$i+50}]]uvwxyz
2914977ccf1Sdrh  do_test json102-[format %d [expr {$i+1300}]] {
2924977ccf1Sdrh    db eval {SELECT json_extract(json_array($::str),'$[0]')==$::str}
2934977ccf1Sdrh  } {1}
2944977ccf1Sdrh}
2954977ccf1Sdrh
2969fa866a8Sdrh#-------------------------------------------------------------------------
2979fa866a8Sdrh# 2017-04-08 ticket b93be8729a895a528e2849fca99f7
2989fa866a8Sdrh# JSON extension accepts invalid numeric values
2999fa866a8Sdrh#
3009fa866a8Sdrh# JSON does not allow leading zeros.  But the JSON extension was
3019fa866a8Sdrh# allowing them.  The following tests verify that the problem is now
3029fa866a8Sdrh# fixed.
3039fa866a8Sdrh#
3049fa866a8Sdrhdo_execsql_test json102-1401 { SELECT json_valid('{"x":01}') } 0
3059fa866a8Sdrhdo_execsql_test json102-1402 { SELECT json_valid('{"x":-01}') } 0
3069fa866a8Sdrhdo_execsql_test json102-1403 { SELECT json_valid('{"x":0}') } 1
3079fa866a8Sdrhdo_execsql_test json102-1404 { SELECT json_valid('{"x":-0}') } 1
3089fa866a8Sdrhdo_execsql_test json102-1405 { SELECT json_valid('{"x":0.1}') } 1
3099fa866a8Sdrhdo_execsql_test json102-1406 { SELECT json_valid('{"x":-0.1}') } 1
3109fa866a8Sdrhdo_execsql_test json102-1407 { SELECT json_valid('{"x":0.0000}') } 1
3119fa866a8Sdrhdo_execsql_test json102-1408 { SELECT json_valid('{"x":-0.0000}') } 1
3129fa866a8Sdrhdo_execsql_test json102-1409 { SELECT json_valid('{"x":01.5}') } 0
3139fa866a8Sdrhdo_execsql_test json102-1410 { SELECT json_valid('{"x":-01.5}') } 0
3149fa866a8Sdrhdo_execsql_test json102-1411 { SELECT json_valid('{"x":00}') } 0
3159fa866a8Sdrhdo_execsql_test json102-1412 { SELECT json_valid('{"x":-00}') } 0
3169fa866a8Sdrh
317e12e24deSdrh#------------------------------------------------------------------------
318e12e24deSdrh# 2017-04-10 ticket 6c9b5514077fed34551f98e64c09a10dc2fc8e16
319e12e24deSdrh# JSON extension accepts strings containing control characters.
320e12e24deSdrh#
321e12e24deSdrh# The JSON spec requires that all control characters be escaped.
322e12e24deSdrh#
323e12e24deSdrhdo_execsql_test json102-1500 {
324e12e24deSdrh  WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<0x20)
325e12e24deSdrh  SELECT x FROM c WHERE json_valid(printf('{"a":"x%sz"}', char(x))) ORDER BY x;
326e12e24deSdrh} {32}
327e12e24deSdrh
3282ac702d8Sdrh# All control characters are escaped
3292ac702d8Sdrh#
3302ac702d8Sdrhdo_execsql_test json102-1501 {
3312ac702d8Sdrh  WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<0x1f)
3322ac702d8Sdrh  SELECT sum(json_valid(json_quote('a'||char(x)||'z'))) FROM c ORDER BY x;
3332ac702d8Sdrh} {31}
3342ac702d8Sdrh
335*d83c90bdSdrh# 2022-01-10 tests for -> and ->> operators
336*d83c90bdSdrh#
337*d83c90bdSdrhreset_db
338*d83c90bdSdrhdo_execsql_test json102-1600 {
339*d83c90bdSdrh  CREATE TABLE t1(id INTEGER PRIMARY KEY, x JSON);
340*d83c90bdSdrh  INSERT INTO t1(id,x) VALUES
341*d83c90bdSdrh   (1, '{"a":null}'),
342*d83c90bdSdrh   (2, '{"a":123}'),
343*d83c90bdSdrh   (3, '{"a":4.5}'),
344*d83c90bdSdrh   (4, '{"a":"six"}'),
345*d83c90bdSdrh   (5, '{"a":[7,8]}'),
346*d83c90bdSdrh   (6, '{"a":{"b":9}}'),
347*d83c90bdSdrh   (7, '{"b":999}');
348*d83c90bdSdrh  SELECT
349*d83c90bdSdrh    id,
350*d83c90bdSdrh    x->'a' AS '->',
351*d83c90bdSdrh    CASE WHEN subtype(x->'a') THEN 'json' ELSE typeof(x->'a') END AS 'type',
352*d83c90bdSdrh    x->>'a' AS '->>',
353*d83c90bdSdrh    CASE WHEN subtype(x->>'a') THEN 'json' ELSE typeof(x->>'a') END AS 'type',
354*d83c90bdSdrh    json_extract(x,'$.a') AS 'json_extract',
355*d83c90bdSdrh    CASE WHEN subtype(json_extract(x,'$.a'))
356*d83c90bdSdrh         THEN 'json' ELSE typeof(json_extract(x,'$.a')) END AS 'type'
357*d83c90bdSdrh    FROM t1 ORDER BY id;
358*d83c90bdSdrh} [list \
359*d83c90bdSdrh  1 null      json {}        null     {}        null          \
360*d83c90bdSdrh  2 123       json 123       integer  123       integer       \
361*d83c90bdSdrh  3 4.5       json 4.5       real     4.5       real          \
362*d83c90bdSdrh  4 {"six"}   json six       text     six       text          \
363*d83c90bdSdrh  5 {[7,8]}   json {[7,8]}   text     {[7,8]}   json          \
364*d83c90bdSdrh  6 {{"b":9}} json {{"b":9}} text     {{"b":9}} json          \
365*d83c90bdSdrh  7 {}        null {}        null     {}        null
366*d83c90bdSdrh]
367*d83c90bdSdrhdo_execsql_test json102-1610 {
368*d83c90bdSdrh  DELETE FROM t1;
369*d83c90bdSdrh  INSERT INTO t1(x) VALUES('[null,123,4.5,"six",[7,8],{"b":9}]');
370*d83c90bdSdrh  WITH c(y) AS (VALUES(0),(1),(2),(3),(4),(5),(6))
371*d83c90bdSdrh  SELECT
372*d83c90bdSdrh    y,
373*d83c90bdSdrh    x->y AS '->',
374*d83c90bdSdrh    CASE WHEN subtype(x->y) THEN 'json' ELSE typeof(x->y) END AS 'type',
375*d83c90bdSdrh    x->>y AS '->>',
376*d83c90bdSdrh    CASE WHEN subtype(x->>y) THEN 'json' ELSE typeof(x->>y) END AS 'type',
377*d83c90bdSdrh    json_extract(x,format('$[%d]',y)) AS 'json_extract',
378*d83c90bdSdrh    CASE WHEN subtype(json_extract(x,format('$[%d]',y)))
379*d83c90bdSdrh      THEN 'json' ELSE typeof(json_extract(x,format('$[%d]',y))) END AS 'type'
380*d83c90bdSdrh  FROM c, t1 ORDER BY y;
381*d83c90bdSdrh} [list \
382*d83c90bdSdrh  0 null      json {}        null    {}        null       \
383*d83c90bdSdrh  1 123       json 123       integer 123       integer    \
384*d83c90bdSdrh  2 4.5       json 4.5       real    4.5       real       \
385*d83c90bdSdrh  3 {"six"}   json six       text    six       text       \
386*d83c90bdSdrh  4 {[7,8]}   json {[7,8]}   text    {[7,8]}   json       \
387*d83c90bdSdrh  5 {{"b":9}} json {{"b":9}} text    {{"b":9}} json       \
388*d83c90bdSdrh  6 {}        null {}        null    {}        null
389*d83c90bdSdrh]
390*d83c90bdSdrh
391852944ebSdrhfinish_test
392