やってみる

アウトプットすべく己を導くためのブログ。その試行錯誤すらたれ流す。

SQLite3学習 JSON拡張(json_type)

 データの型。

成果物

json_type()

 ターミナルで以下コマンドを実行する。

sqlite3

 対話モードにて以下コマンドをコピペし実行。

select json_type('{"a":[2,3.5,true,false,null,"x"]}');
select json_type('{"a":[2,3.5,true,false,null,"x"]}','$');
select json_type('{"a":[2,3.5,true,false,null,"x"]}','$.a');
select json_type('{"a":[2,3.5,true,false,null,"x"]}','$.a[0]');
select json_type('{"a":[2,3.5,true,false,null,"x"]}','$.a[1]');
select json_type('{"a":[2,3.5,true,false,null,"x"]}','$.a[2]');
select json_type('{"a":[2,3.5,true,false,null,"x"]}','$.a[3]');
select json_type('{"a":[2,3.5,true,false,null,"x"]}','$.a[4]');
select json_type('{"a":[2,3.5,true,false,null,"x"]}','$.a[5]');
select json_type('{"a":[2,3.5,true,false,null,"x"]}','$.a[6]');
object
object
array
integer
real
true
false
null
text

 第二引数でJSONパスを指定できる。

json_each()typeと一致する

select * from json_each((select json_extract('{"a":[2,3.5,true,false,null,"x"]}','$.a')));
key         value       type        atom        id          parent      fullkey     path      
----------  ----------  ----------  ----------  ----------  ----------  ----------  ----------
0           2           integer     2           1                       $[0]        $         
1           3.5         real        3.5         2                       $[1]        $         
2           1           true        1           3                       $[2]        $         
3           0           false       0           4                       $[3]        $         
4                       null                    5                       $[4]        $         
5           x           text        x           6                       $[5]        $         

情報源

対象環境

$ uname -a
Linux raspberrypi 4.19.42-v7+ #1218 SMP Tue May 14 00:48:17 BST 2019 armv7l GNU/Linux

前回まで