SQLite Forum

JSON and TCL: is the 'exists' method usable?
Login

JSON and TCL: is the 'exists' method usable?

(1) By anonymous on 2021-08-04 19:59:55 [source]

Using TCL:

% db eval {SELECT json_extract('{"a":15,"b":26}','$.a')}
15
% db exists {SELECT json_extract('{"a":15,"b":26}','$.a')}
1
% db eval {SELECT json_extract('{"a":15,"b":26}','$.c')}
{}
% db exists {SELECT json_extract('{"a":15,"b":26}','$.c')}
1
^------?
Ok, 'null' is an actual value in javascript/JSON, but is there any case in which the 'exists' method will return 0/false, or is it unusable with the JSON extension?

Thanks! dzach

(2) By anonymous on 2021-08-19 11:35:16 in reply to 1 [link] [source]

To answer my own question, yes, the 'exists' method is usable with JSON.

Here is the last line above, returning 0:

db exists {SELECT json_extract('{"a":15,"b":26}','$.c') AS c WHERE c IS NOT NULL}