diff options
author | drh <drh@noemail.net> | 2015-08-28 03:48:04 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2015-08-28 03:48:04 +0000 |
commit | f6ec8d4f4cdd858c052f09091f2bac706ec9cde4 (patch) | |
tree | 8c5e0ae60287c707339c1068df5b94c6dadec601 /ext/misc/json1.c | |
parent | ecb5fedb3f7681fe963f74911e946414e0f65212 (diff) | |
download | sqlite-f6ec8d4f4cdd858c052f09091f2bac706ec9cde4.tar.gz sqlite-f6ec8d4f4cdd858c052f09091f2bac706ec9cde4.zip |
Add the json_check() function, which returns its argument if the argument
is well-formed JSON or which throws an error otherwise.
FossilOrigin-Name: 64abb65d4df11e5b3bcc4afc8e7c18e907c6080a
Diffstat (limited to 'ext/misc/json1.c')
-rw-r--r-- | ext/misc/json1.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/ext/misc/json1.c b/ext/misc/json1.c index dba8ea6da..72ba33be0 100644 --- a/ext/misc/json1.c +++ b/ext/misc/json1.c @@ -1050,6 +1050,28 @@ static void jsonArrayLengthFunc( } /* +** json_check(JSON) +** +** Check the JSON argument to verify that it is well-formed. Return a +** compacted version of the argument (with white-space removed) if the +** argument is well-formed. Through an error if the argument is not +** correctly formatted JSON. +*/ +static void jsonCheckFunc( + sqlite3_context *ctx, + int argc, + sqlite3_value **argv +){ + JsonParse x; /* The parse */ + if( jsonParse(&x, ctx, (const char*)sqlite3_value_text(argv[0])) ){ + sqlite3_result_error(ctx, "malformed JSON", -1); + return; + } + jsonReturn(x.aNode, ctx, argv); + jsonParseReset(&x); +} + +/* ** json_extract(JSON, PATH) ** ** Return the element described by PATH. Return NULL if JSON is not @@ -1780,6 +1802,7 @@ int sqlite3_json_init( { "json_array", -1, 0, jsonArrayFunc }, { "json_array_length", 1, 0, jsonArrayLengthFunc }, { "json_array_length", 2, 0, jsonArrayLengthFunc }, + { "json_check", 1, 0, jsonCheckFunc }, { "json_extract", 2, 0, jsonExtractFunc }, { "json_insert", -1, 0, jsonSetFunc }, { "json_object", -1, 0, jsonObjectFunc }, |