3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
11 # Test cases for JSONB
14 set testdir [file dirname $argv0]
15 source $testdir/tester.tcl
17 do_execsql_test jsonb01-1.1 {
18 CREATE TABLE t1(x JSON BLOB);
19 INSERT INTO t1 VALUES(jsonb('{a:5,b:{x:10,y:11},c:[1,2,3,4]}'));
21 foreach {id path res} {
22 1 {$.a} {{{"b":{"x":10,"y":11},"c":[1,2,3,4]}}}
23 2 {$.b} {{{"a":5,"c":[1,2,3,4]}}}
24 3 {$.c} {{{"a":5,"b":{"x":10,"y":11}}}}
25 4 {$.d} {{{"a":5,"b":{"x":10,"y":11},"c":[1,2,3,4]}}}
26 5 {$.b.x} {{{"a":5,"b":{"y":11},"c":[1,2,3,4]}}}
27 6 {$.b.y} {{{"a":5,"b":{"x":10},"c":[1,2,3,4]}}}
28 7 {$.c[0]} {{{"a":5,"b":{"x":10,"y":11},"c":[2,3,4]}}}
29 8 {$.c[1]} {{{"a":5,"b":{"x":10,"y":11},"c":[1,3,4]}}}
30 9 {$.c[2]} {{{"a":5,"b":{"x":10,"y":11},"c":[1,2,4]}}}
31 10 {$.c[3]} {{{"a":5,"b":{"x":10,"y":11},"c":[1,2,3]}}}
32 11 {$.c[4]} {{{"a":5,"b":{"x":10,"y":11},"c":[1,2,3,4]}}}
33 12 {$.c[#]} {{{"a":5,"b":{"x":10,"y":11},"c":[1,2,3,4]}}}
34 13 {$.c[#-1]} {{{"a":5,"b":{"x":10,"y":11},"c":[1,2,3]}}}
35 14 {$.c[#-2]} {{{"a":5,"b":{"x":10,"y":11},"c":[1,2,4]}}}
36 15 {$.c[#-3]} {{{"a":5,"b":{"x":10,"y":11},"c":[1,3,4]}}}
37 16 {$.c[#-4]} {{{"a":5,"b":{"x":10,"y":11},"c":[2,3,4]}}}
38 17 {$.c[#-5]} {{{"a":5,"b":{"x":10,"y":11},"c":[1,2,3,4]}}}
39 18 {$.c[#-6]} {{{"a":5,"b":{"x":10,"y":11},"c":[1,2,3,4]}}}
41 do_execsql_test jsonb01-1.2.$id.1 {
42 SELECT json(jsonb_remove(x,$path)) FROM t1;
44 do_execsql_test jsonb01-1.2.$id.2 {
45 SELECT json_remove(x,$path) FROM t1;