SQLite Forum

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

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

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

Using TCL:

% db eval {SELECT json_extract('{"a":15,"b":26}','$.a')}
% db exists {SELECT json_extract('{"a":15,"b":26}','$.a')}
% db eval {SELECT json_extract('{"a":15,"b":26}','$.c')}
% db exists {SELECT json_extract('{"a":15,"b":26}','$.c')}
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 [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}