1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-09 14:21:03 +03:00

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
This commit is contained in:
drh
2023-04-25 21:24:20 +00:00
parent be5bada4d0
commit 058f3dbb27
3 changed files with 29 additions and 14 deletions

View File

@@ -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;
@@ -1997,6 +2004,16 @@ static void jsonValidFunc(
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 && p->has5==0);
}
static void jsonValid5Func(
sqlite3_context *ctx,
int argc,
sqlite3_value **argv
){
JsonParse *p; /* The parse */
UNUSED_PARAMETER(argc);
@@ -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),