blob: 7ae99353bfe5b97945f12272973d6c7872108c83 [file] [log] [blame]
drh852944e2015-09-10 03:29:11 +00001# 2015-08-12
2#
3# The author disclaims copyright to this source code. In place of
4# a legal notice, here is a blessing:
5#
6# May you do good and not evil.
7# May you find forgiveness for yourself and forgive others.
8# May you share freely, never taking more than you give.
9#
10#***********************************************************************
11# This file implements tests for JSON SQL functions extension to the
12# SQLite library.
13#
14# This file contains tests automatically generated from the json1
15# documentation.
16#
17
18set testdir [file dirname $argv0]
19source $testdir/tester.tcl
20
drhc306e082015-10-08 23:37:00 +000021ifcapable !json1 {
22 finish_test
23 return
24}
25
drh852944e2015-09-10 03:29:11 +000026do_execsql_test json102-100 {
drhe98b6fa2015-09-11 15:32:33 +000027 SELECT json_object('ex','[52,3.14159]');
28} {{{"ex":"[52,3.14159]"}}}
29do_execsql_test json102-110 {
30 SELECT json_object('ex',json('[52,3.14159]'));
31} {{{"ex":[52,3.14159]}}}
32do_execsql_test json102-120 {
33 SELECT json_object('ex',json_array(52,3.14159));
34} {{{"ex":[52,3.14159]}}}
35do_execsql_test json102-130 {
drh12b3b892015-09-11 01:22:41 +000036 SELECT json(' { "this" : "is", "a": [ "test" ] } ');
37} {{{"this":"is","a":["test"]}}}
drhe98b6fa2015-09-11 15:32:33 +000038do_execsql_test json102-140 {
drh852944e2015-09-10 03:29:11 +000039 SELECT json_array(1,2,'3',4);
40} {{[1,2,"3",4]}}
drhe98b6fa2015-09-11 15:32:33 +000041do_execsql_test json102-150 {
drh852944e2015-09-10 03:29:11 +000042 SELECT json_array('[1,2]');
43} {{["[1,2]"]}}
drhe98b6fa2015-09-11 15:32:33 +000044do_execsql_test json102-160 {
drh12b3b892015-09-11 01:22:41 +000045 SELECT json_array(json_array(1,2));
46} {{[[1,2]]}}
drhe98b6fa2015-09-11 15:32:33 +000047do_execsql_test json102-170 {
drh852944e2015-09-10 03:29:11 +000048 SELECT json_array(1,null,'3','[4,5]','{"six":7.7}');
49} {{[1,null,"3","[4,5]","{\"six\":7.7}"]}}
drhe98b6fa2015-09-11 15:32:33 +000050do_execsql_test json102-180 {
drh12b3b892015-09-11 01:22:41 +000051 SELECT json_array(1,null,'3',json('[4,5]'),json('{"six":7.7}'));
52} {{[1,null,"3",[4,5],{"six":7.7}]}}
drhe98b6fa2015-09-11 15:32:33 +000053do_execsql_test json102-190 {
drh852944e2015-09-10 03:29:11 +000054 SELECT json_array_length('[1,2,3,4]');
55} {{4}}
drhe98b6fa2015-09-11 15:32:33 +000056do_execsql_test json102-200 {
57 SELECT json_array_length('[1,2,3,4]', '$');
58} {{4}}
59do_execsql_test json102-210 {
60 SELECT json_array_length('[1,2,3,4]', '$[2]');
61} {{0}}
62do_execsql_test json102-220 {
drh852944e2015-09-10 03:29:11 +000063 SELECT json_array_length('{"one":[1,2,3]}');
64} {{0}}
drhe98b6fa2015-09-11 15:32:33 +000065do_execsql_test json102-230 {
drh852944e2015-09-10 03:29:11 +000066 SELECT json_array_length('{"one":[1,2,3]}', '$.one');
67} {{3}}
drh12b3b892015-09-11 01:22:41 +000068do_execsql_test json102-240 {
drhe98b6fa2015-09-11 15:32:33 +000069 SELECT json_array_length('{"one":[1,2,3]}', '$.two');
drh852944e2015-09-10 03:29:11 +000070} {{}}
drh12b3b892015-09-11 01:22:41 +000071do_execsql_test json102-250 {
drhe98b6fa2015-09-11 15:32:33 +000072 SELECT json_extract('{"a":2,"c":[4,5,{"f":7}]}', '$');
73} {{{"a":2,"c":[4,5,{"f":7}]}}}
drh12b9fa92022-01-07 15:47:12 +000074do_execsql_test json102-251 {
drh338b1fd2022-01-07 17:08:48 +000075 SELECT json_nextract('{"a":2,"c":[4,5,{"f":7}]}', '$');
76} {{{"a":2,"c":[4,5,{"f":7}]}}}
77do_execsql_test json102-252 {
drh12b9fa92022-01-07 15:47:12 +000078 SELECT '{"a":2,"c":[4,5,{"f":7}]}' -> '$';
79} {{{"a":2,"c":[4,5,{"f":7}]}}}
drhe98b6fa2015-09-11 15:32:33 +000080do_execsql_test json102-260 {
81 SELECT json_extract('{"a":2,"c":[4,5,{"f":7}]}', '$.c');
82} {{[4,5,{"f":7}]}}
drh12b9fa92022-01-07 15:47:12 +000083do_execsql_test json102-261 {
84 SELECT '{"a":2,"c":[4,5,{"f":7}]}' -> '$.c';
85} {{[4,5,{"f":7}]}}
86do_execsql_test json102-262 {
87 SELECT '{"a":2,"c":[4,5,{"f":7}]}' -> 'c';
88} {{[4,5,{"f":7}]}}
drh338b1fd2022-01-07 17:08:48 +000089do_catchsql_test json102-265 {
90 SELECT json_extract('[1,2,3', '$[2]');
91} {1 {malformed JSON}}
92do_catchsql_test json102-266 {
93 SELECT json_nextract('[1,2,3', '$[2]');
94} {0 {{}}}
95do_catchsql_test json102-267 {
96 SELECT json_extract('[1,2,3', '$');
97} {1 {malformed JSON}}
98do_catchsql_test json102-268 {
99 SELECT json_nextract('[1,2,3', '$');
100} {0 {{"[1,2,3"}}}
drh9956c182022-01-07 17:14:35 +0000101do_catchsql_test json102-269a {
drha3f51d72022-01-07 17:26:40 +0000102 SELECT '[1,2,3' ->> '$';
drh9956c182022-01-07 17:14:35 +0000103} {1 {malformed JSON}}
104do_catchsql_test json102-269b {
drha3f51d72022-01-07 17:26:40 +0000105 SELECT '[1,2,3' -> '$';
drh338b1fd2022-01-07 17:08:48 +0000106} {0 {{"[1,2,3"}}}
107
drhe98b6fa2015-09-11 15:32:33 +0000108do_execsql_test json102-270 {
109 SELECT json_extract('{"a":2,"c":[4,5,{"f":7}]}', '$.c[2]');
110} {{{"f":7}}}
drh12b9fa92022-01-07 15:47:12 +0000111do_execsql_test json102-271 {
112 SELECT '{"a":2,"c":[4,5,{"f":7}]}' -> '$.c[2]';
113} {{{"f":7}}}
114do_execsql_test json102-272 {
115 SELECT '{"a":2,"c":[4,5,{"f":7}]}' -> 'c' -> 2;
116} {{{"f":7}}}
drhe98b6fa2015-09-11 15:32:33 +0000117do_execsql_test json102-280 {
118 SELECT json_extract('{"a":2,"c":[4,5,{"f":7}]}', '$.c[2].f');
119} {{7}}
drh12b9fa92022-01-07 15:47:12 +0000120do_execsql_test json102-281 {
121 SELECT '{"a":2,"c":[4,5,{"f":7}]}' -> 'c' -> 2 -> 'f';
122} {{7}}
123do_execsql_test json102-282 {
124 SELECT '{"a":2,"c":[4,5,{"f":7}]}' -> 'c' -> '[2]' -> 'f';
125} {{7}}
drhe98b6fa2015-09-11 15:32:33 +0000126do_execsql_test json102-290 {
127 SELECT json_extract('{"a":2,"c":[4,5],"f":7}','$.c','$.a');
128} {{[[4,5],2]}}
129do_execsql_test json102-300 {
130 SELECT json_extract('{"a":2,"c":[4,5,{"f":7}]}', '$.x');
131} {{}}
drh12b9fa92022-01-07 15:47:12 +0000132do_execsql_test json102-301 {
133 SELECT '{"a":2,"c":[4,5,{"f":7}]}' -> 'x';
134} {{}}
135do_execsql_test json102-302 {
136 SELECT '{"a":2,"c":[4,5,{"f":7}]}' -> NULL;
137} {{}}
drhe98b6fa2015-09-11 15:32:33 +0000138do_execsql_test json102-310 {
139 SELECT json_extract('{"a":2,"c":[4,5,{"f":7}]}', '$.x', '$.a');
140} {{[null,2]}}
141do_execsql_test json102-320 {
drh852944e2015-09-10 03:29:11 +0000142 SELECT json_insert('{"a":2,"c":4}', '$.a', 99);
143} {{{"a":2,"c":4}}}
drhe98b6fa2015-09-11 15:32:33 +0000144do_execsql_test json102-330 {
drh852944e2015-09-10 03:29:11 +0000145 SELECT json_insert('{"a":2,"c":4}', '$.e', 99);
146} {{{"a":2,"c":4,"e":99}}}
drhe98b6fa2015-09-11 15:32:33 +0000147do_execsql_test json102-340 {
drh852944e2015-09-10 03:29:11 +0000148 SELECT json_replace('{"a":2,"c":4}', '$.a', 99);
149} {{{"a":99,"c":4}}}
drhe98b6fa2015-09-11 15:32:33 +0000150do_execsql_test json102-350 {
drh852944e2015-09-10 03:29:11 +0000151 SELECT json_replace('{"a":2,"c":4}', '$.e', 99);
152} {{{"a":2,"c":4}}}
drhe98b6fa2015-09-11 15:32:33 +0000153do_execsql_test json102-360 {
drh852944e2015-09-10 03:29:11 +0000154 SELECT json_set('{"a":2,"c":4}', '$.a', 99);
155} {{{"a":99,"c":4}}}
drhe98b6fa2015-09-11 15:32:33 +0000156do_execsql_test json102-370 {
drh852944e2015-09-10 03:29:11 +0000157 SELECT json_set('{"a":2,"c":4}', '$.e', 99);
158} {{{"a":2,"c":4,"e":99}}}
drhe98b6fa2015-09-11 15:32:33 +0000159do_execsql_test json102-380 {
drh12b3b892015-09-11 01:22:41 +0000160 SELECT json_set('{"a":2,"c":4}', '$.c', '[97,96]');
161} {{{"a":2,"c":"[97,96]"}}}
drhe98b6fa2015-09-11 15:32:33 +0000162do_execsql_test json102-390 {
drh12b3b892015-09-11 01:22:41 +0000163 SELECT json_set('{"a":2,"c":4}', '$.c', json('[97,96]'));
164} {{{"a":2,"c":[97,96]}}}
drhe98b6fa2015-09-11 15:32:33 +0000165do_execsql_test json102-400 {
drh12b3b892015-09-11 01:22:41 +0000166 SELECT json_set('{"a":2,"c":4}', '$.c', json_array(97,96));
167} {{{"a":2,"c":[97,96]}}}
drhe98b6fa2015-09-11 15:32:33 +0000168do_execsql_test json102-410 {
drh852944e2015-09-10 03:29:11 +0000169 SELECT json_object('a',2,'c',4);
170} {{{"a":2,"c":4}}}
drhe98b6fa2015-09-11 15:32:33 +0000171do_execsql_test json102-420 {
drh852944e2015-09-10 03:29:11 +0000172 SELECT json_object('a',2,'c','{e:5}');
173} {{{"a":2,"c":"{e:5}"}}}
drhe98b6fa2015-09-11 15:32:33 +0000174do_execsql_test json102-430 {
drh12b3b892015-09-11 01:22:41 +0000175 SELECT json_object('a',2,'c',json_object('e',5));
176} {{{"a":2,"c":{"e":5}}}}
drhe98b6fa2015-09-11 15:32:33 +0000177do_execsql_test json102-440 {
drh852944e2015-09-10 03:29:11 +0000178 SELECT json_remove('[0,1,2,3,4]','$[2]');
179} {{[0,1,3,4]}}
drhe98b6fa2015-09-11 15:32:33 +0000180do_execsql_test json102-450 {
drh852944e2015-09-10 03:29:11 +0000181 SELECT json_remove('[0,1,2,3,4]','$[2]','$[0]');
182} {{[1,3,4]}}
drhe98b6fa2015-09-11 15:32:33 +0000183do_execsql_test json102-460 {
drh852944e2015-09-10 03:29:11 +0000184 SELECT json_remove('[0,1,2,3,4]','$[0]','$[2]');
185} {{[1,2,4]}}
drhe98b6fa2015-09-11 15:32:33 +0000186do_execsql_test json102-470 {
drh852944e2015-09-10 03:29:11 +0000187 SELECT json_remove('{"x":25,"y":42}');
188} {{{"x":25,"y":42}}}
drhe98b6fa2015-09-11 15:32:33 +0000189do_execsql_test json102-480 {
drh852944e2015-09-10 03:29:11 +0000190 SELECT json_remove('{"x":25,"y":42}','$.z');
191} {{{"x":25,"y":42}}}
drhe98b6fa2015-09-11 15:32:33 +0000192do_execsql_test json102-490 {
drh852944e2015-09-10 03:29:11 +0000193 SELECT json_remove('{"x":25,"y":42}','$.y');
194} {{{"x":25}}}
drhe98b6fa2015-09-11 15:32:33 +0000195do_execsql_test json102-500 {
drh852944e2015-09-10 03:29:11 +0000196 SELECT json_remove('{"x":25,"y":42}','$');
197} {{}}
drhe98b6fa2015-09-11 15:32:33 +0000198do_execsql_test json102-510 {
drh852944e2015-09-10 03:29:11 +0000199 SELECT json_type('{"a":[2,3.5,true,false,null,"x"]}');
200} {{object}}
drha4e4e182022-01-07 16:03:00 +0000201do_execsql_test json102-511 {
202 SELECT json_ntype('{"a":[2,3.5,true,false,null,"x"]}');
203} {{object}}
drhe98b6fa2015-09-11 15:32:33 +0000204do_execsql_test json102-520 {
drh852944e2015-09-10 03:29:11 +0000205 SELECT json_type('{"a":[2,3.5,true,false,null,"x"]}','$');
206} {{object}}
drhe98b6fa2015-09-11 15:32:33 +0000207do_execsql_test json102-530 {
drh852944e2015-09-10 03:29:11 +0000208 SELECT json_type('{"a":[2,3.5,true,false,null,"x"]}','$.a');
209} {{array}}
drhe98b6fa2015-09-11 15:32:33 +0000210do_execsql_test json102-540 {
drh852944e2015-09-10 03:29:11 +0000211 SELECT json_type('{"a":[2,3.5,true,false,null,"x"]}','$.a[0]');
212} {{integer}}
drhe98b6fa2015-09-11 15:32:33 +0000213do_execsql_test json102-550 {
drh852944e2015-09-10 03:29:11 +0000214 SELECT json_type('{"a":[2,3.5,true,false,null,"x"]}','$.a[1]');
215} {{real}}
drhe98b6fa2015-09-11 15:32:33 +0000216do_execsql_test json102-560 {
drh852944e2015-09-10 03:29:11 +0000217 SELECT json_type('{"a":[2,3.5,true,false,null,"x"]}','$.a[2]');
218} {{true}}
drhe98b6fa2015-09-11 15:32:33 +0000219do_execsql_test json102-570 {
drh852944e2015-09-10 03:29:11 +0000220 SELECT json_type('{"a":[2,3.5,true,false,null,"x"]}','$.a[3]');
221} {{false}}
drhe98b6fa2015-09-11 15:32:33 +0000222do_execsql_test json102-580 {
drh852944e2015-09-10 03:29:11 +0000223 SELECT json_type('{"a":[2,3.5,true,false,null,"x"]}','$.a[4]');
224} {{null}}
drhe98b6fa2015-09-11 15:32:33 +0000225do_execsql_test json102-590 {
drh852944e2015-09-10 03:29:11 +0000226 SELECT json_type('{"a":[2,3.5,true,false,null,"x"]}','$.a[5]');
227} {{text}}
drhe98b6fa2015-09-11 15:32:33 +0000228do_execsql_test json102-600 {
drh852944e2015-09-10 03:29:11 +0000229 SELECT json_type('{"a":[2,3.5,true,false,null,"x"]}','$.a[6]');
230} {{}}
drhe98b6fa2015-09-11 15:32:33 +0000231do_execsql_test json102-610 {
drh12b3b892015-09-11 01:22:41 +0000232 SELECT json_valid(char(123)||'"x":35'||char(125));
drh852944e2015-09-10 03:29:11 +0000233} {{1}}
drhe98b6fa2015-09-11 15:32:33 +0000234do_execsql_test json102-620 {
drh12b3b892015-09-11 01:22:41 +0000235 SELECT json_valid(char(123)||'"x":35');
drh852944e2015-09-10 03:29:11 +0000236} {{0}}
drha4e4e182022-01-07 16:03:00 +0000237do_catchsql_test json102-630 {
238 SELECT json_type('["a",');
239} {1 {malformed JSON}}
240do_catchsql_test json102-631 {
241 SELECT json_ntype('["a",');
242} {0 {{}}}
drh852944e2015-09-10 03:29:11 +0000243
drhe6f52782015-09-10 15:22:35 +0000244ifcapable vtab {
drh12b3b892015-09-11 01:22:41 +0000245do_execsql_test json102-1000 {
drh852944e2015-09-10 03:29:11 +0000246 CREATE TABLE user(name,phone);
247 INSERT INTO user(name,phone) VALUES
248 ('Alice','["919-555-2345","804-555-3621"]'),
249 ('Bob','["201-555-8872"]'),
250 ('Cindy','["704-555-9983"]'),
251 ('Dave','["336-555-8421","704-555-4321","803-911-4421"]');
252 SELECT DISTINCT user.name
253 FROM user, json_each(user.phone)
254 WHERE json_each.value LIKE '704-%'
255 ORDER BY 1;
256} {Cindy Dave}
257
drh12b3b892015-09-11 01:22:41 +0000258do_execsql_test json102-1010 {
drh852944e2015-09-10 03:29:11 +0000259 UPDATE user
260 SET phone=json_extract(phone,'$[0]')
261 WHERE json_array_length(phone)<2;
262 SELECT name, substr(phone,1,5) FROM user ORDER BY name;
263} {Alice {["919} Bob 201-5 Cindy 704-5 Dave {["336}}
drh12b3b892015-09-11 01:22:41 +0000264do_execsql_test json102-1011 {
drh852944e2015-09-10 03:29:11 +0000265 SELECT name FROM user WHERE phone LIKE '704-%'
266 UNION
267 SELECT user.name
268 FROM user, json_each(user.phone)
269 WHERE json_valid(user.phone)
270 AND json_each.value LIKE '704-%';
271} {Cindy Dave}
272
drh12b3b892015-09-11 01:22:41 +0000273do_execsql_test json102-1100 {
drh852944e2015-09-10 03:29:11 +0000274 CREATE TABLE big(json JSON);
275 INSERT INTO big(json) VALUES('{
276 "id":123,
277 "stuff":[1,2,3,4],
278 "partlist":[
279 {"uuid":"bb108722-572e-11e5-9320-7f3b63a4ca74"},
280 {"uuid":"c690dc14-572e-11e5-95f9-dfc8861fd535"},
281 {"subassembly":[
282 {"uuid":"6fa5181e-5721-11e5-a04e-57f3d7b32808"}
283 ]}
284 ]
285 }');
286 INSERT INTO big(json) VALUES('{
287 "id":456,
288 "stuff":["hello","world","xyzzy"],
289 "partlist":[
290 {"uuid":false},
291 {"uuid":"c690dc14-572e-11e5-95f9-dfc8861fd535"}
292 ]
293 }');
294} {}
295set correct_answer [list \
296 1 {$.id} 123 \
297 1 {$.stuff[0]} 1 \
298 1 {$.stuff[1]} 2 \
299 1 {$.stuff[2]} 3 \
300 1 {$.stuff[3]} 4 \
301 1 {$.partlist[0].uuid} bb108722-572e-11e5-9320-7f3b63a4ca74 \
302 1 {$.partlist[1].uuid} c690dc14-572e-11e5-95f9-dfc8861fd535 \
303 1 {$.partlist[2].subassembly[0].uuid} 6fa5181e-5721-11e5-a04e-57f3d7b32808 \
304 2 {$.id} 456 \
305 2 {$.stuff[0]} hello \
306 2 {$.stuff[1]} world \
307 2 {$.stuff[2]} xyzzy \
308 2 {$.partlist[0].uuid} 0 \
309 2 {$.partlist[1].uuid} c690dc14-572e-11e5-95f9-dfc8861fd535]
drh12b3b892015-09-11 01:22:41 +0000310do_execsql_test json102-1110 {
drh852944e2015-09-10 03:29:11 +0000311 SELECT big.rowid, fullkey, value
312 FROM big, json_tree(big.json)
313 WHERE json_tree.type NOT IN ('object','array')
314 ORDER BY +big.rowid, +json_tree.id
315} $correct_answer
drh12b3b892015-09-11 01:22:41 +0000316do_execsql_test json102-1120 {
drh852944e2015-09-10 03:29:11 +0000317 SELECT big.rowid, fullkey, atom
318 FROM big, json_tree(big.json)
319 WHERE atom IS NOT NULL
320 ORDER BY +big.rowid, +json_tree.id
321} $correct_answer
322
drh12b3b892015-09-11 01:22:41 +0000323do_execsql_test json102-1130 {
drh852944e2015-09-10 03:29:11 +0000324 SELECT DISTINCT json_extract(big.json,'$.id')
325 FROM big, json_tree(big.json,'$.partlist')
326 WHERE json_tree.key='uuid'
327 AND json_tree.value='6fa5181e-5721-11e5-a04e-57f3d7b32808';
328} {123}
drh12b3b892015-09-11 01:22:41 +0000329do_execsql_test json102-1131 {
drh852944e2015-09-10 03:29:11 +0000330 SELECT DISTINCT json_extract(big.json,'$.id')
331 FROM big, json_tree(big.json,'$')
332 WHERE json_tree.key='uuid'
333 AND json_tree.value='6fa5181e-5721-11e5-a04e-57f3d7b32808';
334} {123}
drh12b3b892015-09-11 01:22:41 +0000335do_execsql_test json102-1132 {
drh852944e2015-09-10 03:29:11 +0000336 SELECT DISTINCT json_extract(big.json,'$.id')
337 FROM big, json_tree(big.json)
338 WHERE json_tree.key='uuid'
339 AND json_tree.value='6fa5181e-5721-11e5-a04e-57f3d7b32808';
340} {123}
drhe6f52782015-09-10 15:22:35 +0000341} ;# end ifcapable vtab
drh852944e2015-09-10 03:29:11 +0000342
dan2e8f5512015-09-17 17:21:09 +0000343#-------------------------------------------------------------------------
344# Test that json_valid() correctly identifies non-ascii range
345# characters as non-whitespace.
346#
347do_execsql_test json102-1201 { SELECT json_valid(char(32) || '"xyz"') } 1
348do_execsql_test json102-1202 { SELECT json_valid(char(200) || '"xyz"') } 0
349
drh4977ccf2015-09-19 11:57:26 +0000350# Off-by-one error in jsonAppendString()
351#
352for {set i 0} {$i<100} {incr i} {
353 set str abcdef[string repeat \" [expr {$i+50}]]uvwxyz
354 do_test json102-[format %d [expr {$i+1300}]] {
355 db eval {SELECT json_extract(json_array($::str),'$[0]')==$::str}
356 } {1}
357}
358
drh9fa866a2017-04-08 18:18:22 +0000359#-------------------------------------------------------------------------
360# 2017-04-08 ticket b93be8729a895a528e2849fca99f7
361# JSON extension accepts invalid numeric values
362#
363# JSON does not allow leading zeros. But the JSON extension was
364# allowing them. The following tests verify that the problem is now
365# fixed.
366#
367do_execsql_test json102-1401 { SELECT json_valid('{"x":01}') } 0
368do_execsql_test json102-1402 { SELECT json_valid('{"x":-01}') } 0
369do_execsql_test json102-1403 { SELECT json_valid('{"x":0}') } 1
370do_execsql_test json102-1404 { SELECT json_valid('{"x":-0}') } 1
371do_execsql_test json102-1405 { SELECT json_valid('{"x":0.1}') } 1
372do_execsql_test json102-1406 { SELECT json_valid('{"x":-0.1}') } 1
373do_execsql_test json102-1407 { SELECT json_valid('{"x":0.0000}') } 1
374do_execsql_test json102-1408 { SELECT json_valid('{"x":-0.0000}') } 1
375do_execsql_test json102-1409 { SELECT json_valid('{"x":01.5}') } 0
376do_execsql_test json102-1410 { SELECT json_valid('{"x":-01.5}') } 0
377do_execsql_test json102-1411 { SELECT json_valid('{"x":00}') } 0
378do_execsql_test json102-1412 { SELECT json_valid('{"x":-00}') } 0
379
drhe12e24d2017-04-10 12:25:05 +0000380#------------------------------------------------------------------------
381# 2017-04-10 ticket 6c9b5514077fed34551f98e64c09a10dc2fc8e16
382# JSON extension accepts strings containing control characters.
383#
384# The JSON spec requires that all control characters be escaped.
385#
386do_execsql_test json102-1500 {
387 WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<0x20)
388 SELECT x FROM c WHERE json_valid(printf('{"a":"x%sz"}', char(x))) ORDER BY x;
389} {32}
390
drh2ac702d2017-04-10 12:31:15 +0000391# All control characters are escaped
392#
393do_execsql_test json102-1501 {
394 WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<0x1f)
395 SELECT sum(json_valid(json_quote('a'||char(x)||'z'))) FROM c ORDER BY x;
396} {31}
397
drh852944e2015-09-10 03:29:11 +0000398finish_test