Details
-
Bug
-
Status: Open (View Workflow)
-
Minor
-
Resolution: Unresolved
-
11.4.4
Description
In the knowledgebase, JSON_VALUE is listed as returning NULL if json_doc is not a valid JSON document. However if json_doc is invalid but path refers to a position before whatever makes the JSON document invalid, the scalar specified by the path is still returned.
Test script:
SET @json = '{"a":"z","b":y,"c":"x"}'; |
SELECT JSON_VALID(@json), JSON_VALUE(@json, '$.a'), JSON_VALUE(@json, '$.b'); |
Returns:
+-------------------+--------------------------+--------------------------+
|
| JSON_VALID(@json) | JSON_VALUE(@json, '$.a') | JSON_VALUE(@json, '$.b') |
|
+-------------------+--------------------------+--------------------------+
|
| 0 | z | NULL |
|
+-------------------+--------------------------+--------------------------+
|
This might be considered 'good' behaviour, but if this won't be fixed; it might make sense to update the knowledgebase to note this in the return type. I discovered this when using the function in a check constraint where I needed it to be valid JSON and one of the scalar values to meet other criteria - in cases like that it would be good to know that JSON_VALID must be used as well.