diff options
author | drh <> | 2023-04-25 21:24:20 +0000 |
---|---|---|
committer | drh <> | 2023-04-25 21:24:20 +0000 |
commit | 058f3dbb270e9784f72cf9deb7f176fa194e56fe (patch) | |
tree | 18592c91e22c397982afc9443e482c19586d2cd3 /src | |
parent | be5bada4d039adbd7608cb087dbdad948374548c (diff) | |
download | sqlite-058f3dbb270e9784f72cf9deb7f176fa194e56fe.tar.gz sqlite-058f3dbb270e9784f72cf9deb7f176fa194e56fe.zip |
The json_valid() function only returns true for pure JSON. JSON5 (or
at least that subset of JSON5 that has been so far implemented) is accepted
by all routines, but json_valid() still returns false for JSON5 inputs.
The new json_valid5(X) routine returns true or false if X is or is not valid
JSON5. All of this is experimental and subject to change.
FossilOrigin-Name: 5d33ab77800765c8b3a13ffcc02ba8a348d71b2b425924560418b517d723494d
Diffstat (limited to 'src')
-rw-r--r-- | src/json.c | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/src/json.c b/src/json.c index 4c68608de..b201fdde5 100644 --- a/src/json.c +++ b/src/json.c @@ -130,9 +130,10 @@ struct JsonParse { JsonNode *aNode; /* Array of nodes containing the parse */ const char *zJson; /* Original JSON string */ u32 *aUp; /* Index of parent of each node */ - u8 oom; /* Set to true if out of memory */ - u8 nErr; /* Number of errors seen */ u16 iDepth; /* Nesting depth */ + u8 nErr; /* Number of errors seen */ + u8 oom; /* Set to true if out of memory */ + u8 has5; /* True if input has JSON5 features */ int nJson; /* Length of the zJson string in bytes */ u32 iHold; /* Replace cache line with the lowest iHold value */ }; @@ -804,7 +805,10 @@ static int jsonParseValue(JsonParse *pParse, u32 i){ x = jsonParseValue(pParse, j); if( x<0 ){ pParse->iDepth--; - if( x==(-2) ) break; + if( x==(-2) ){ + if( pParse->nNode!=(u32)iThis+1 ) pParse->has5 = 1; + break; + } return -1; } if( pParse->oom ) return -1; @@ -838,7 +842,10 @@ static int jsonParseValue(JsonParse *pParse, u32 i){ x = jsonParseValue(pParse, j); pParse->iDepth--; if( x<0 ){ - if( x==(-3) ) break; + if( x==(-3) ){ + if( pParse->nNode!=(u32)iThis+1 ) pParse->has5 = 1; + break; + } return -1; } j = x; @@ -2001,6 +2008,16 @@ static void jsonValidFunc( JsonParse *p; /* The parse */ UNUSED_PARAMETER(argc); p = jsonParseCached(ctx, argv, 0); + sqlite3_result_int(ctx, p!=0 && p->has5==0); +} +static void jsonValid5Func( + sqlite3_context *ctx, + int argc, + sqlite3_value **argv +){ + JsonParse *p; /* The parse */ + UNUSED_PARAMETER(argc); + p = jsonParseCached(ctx, argv, 0); sqlite3_result_int(ctx, p!=0); } @@ -2725,6 +2742,7 @@ void sqlite3RegisterJsonFunctions(void){ JFUNCTION(json_type, 1, 0, jsonTypeFunc), JFUNCTION(json_type, 2, 0, jsonTypeFunc), JFUNCTION(json_valid, 1, 0, jsonValidFunc), + JFUNCTION(json_valid5, 1, 0, jsonValid5Func), #if SQLITE_DEBUG JFUNCTION(json_parse, 1, 0, jsonParseFunc), JFUNCTION(json_test1, 1, 0, jsonTest1Func), |