JSON_ VALID
Checks if a string is a well-formed JSON document.
This function returns true if the value in the given column is a valid JSON string, and false otherwise. Unlike JSON, it does not throw an error for malformed JSON, making it suitable for validation checks.
An optional flag argument can be provided to specify validation rules according to RFC 8259 (when flag is 1). By default, (or with flag as 0), it allows top-level JSON values that are not objects or arrays, which is a common extension.
Example:
val jsonCol = textColumn("json_data")
// Check for any well-formed JSON
// SELECT JSON_VALID(json_data) FROM MyTable WHERE ...
select(JSON_VALID(jsonCol)).from(MyTable).where(...).execute()
// Check for strict RFC 8259 compliance (top-level must be object or array)
// SELECT JSON_VALID(json_data, 1) FROM MyTable WHERE ...
select(JSON_VALID(jsonCol, 1)).from(MyTable).where(...).execute()Return
A KQLiteColumn of type Boolean that is true if the JSON is valid, false otherwise.
Author
MOHAMMAD AZIM ANSARI
Parameters
The column containing the string to be validated as JSON.
An optional integer flag for validation mode. - 0 (default): Allows any valid JSON value. - 1: Enforces strict RFC 8259 (top-level must be an object or array).