JSON_ERROR_POSITION

Returns the 1-based index of the character where a syntax error occurred in malformed JSON.

This function is useful for debugging malformed JSON text. It analyzes the given JSON string and, if it is not well-formed, returns the character position of the syntax error. If the JSON is well-formed, it returns 0.

This function is a recent addition to SQLite and might not be available in older versions. It is only available if SQLite is compiled with the -DSQLITE_ENABLE_JSON_ERROR_POSITION compile-time option.

Example:

// Assuming a column 'invalidJson' contains '{"key": "value",}'
// The trailing comma is an error.
val invalidJsonCol = textColumn("invalidJson")

// SELECT JSON_ERROR_POSITION(invalidJson)
// Result might be 17 (depending on the exact content)
select(JSON_ERROR_POSITION(invalidJsonCol)).from(MyTable).execute()

// Example with well-formed JSON
val validJson = JSON("""{"key": "value"}""")
// SELECT JSON_ERROR_POSITION('{"key": "value"}')
// Result: 0
select(JSON_ERROR_POSITION(validJson)).execute()

Return

A KQLiteColumn of type Int representing the 1-based character index of a syntax error, or 0 if the JSON is valid.

Author

MOHAMMAD AZIM ANSARI

Parameters

json

The KQLiteJson column containing the JSON text to validate.

See also