SQLite Forum

Timeline
Login

2 forum posts by user EternityForest

2020-11-12
08:05 Reply: Document or specify what json_extract does with nonexistant keys? (artifact: d23ebcd6b1 user: EternityForest)

Ah, I missed that line in the docs! Thank you for pointing that out!

Should I assume, that since it is documented as such, I can continue relying on it to return NULL instead of an error, as a way to test for existence?

2020-10-29
03:06 Post: Document or specify what json_extract does with nonexistant keys? (artifact: 25c857652d user: EternityForest)

Hello All! Right now, json_extract says:

4.4. The json_extract() function
The json_extract(X,P1,P2,...) extracts and returns one or more values from the well-formed JSON at X. 

If only a single path P1 is provided, then the SQL datatype of the result is NULL for a JSON null, INTEGER or REAL for a JSON numeric value, an INTEGER zero for a JSON false value, an INTEGER one for a JSON true value, the dequoted text for a JSON string value, and a text representation for JSON object and array values. 

If there are multiple path arguments (P1, P2, and so forth) then this routine returns SQLite text which is a well-formed JSON array holding the various values.

But if I try to access a nonexistant key, I get null, not an error. This seems to be what other DBs do, and is very convenient in my particular case, but nonetheless it is still undefined behavior.

Is the current behavior "How things should be"? If so, should the documentation change to reflect that? It's a bit of a "hidden feature" now.

Thanks all!