SQLite JSON Functions
SQLite has no separate JSON storage class: JSON is commonly stored as TEXT. Since SQLite 3.45.0, it can also be stored as SQLite’s JSONB representation in a BLOB. SQLite JSONB is an internal SQLite format and is not binary-compatible with PostgreSQL JSONB.
Use the references below to create and aggregate JSON, extract or update values by path, validate JSON, and expand arrays and objects into rows. See the SQLite JSON documentation for supported formats, version requirements, and full function behavior.
For practical guidance on choosing JSON text or JSONB, see SQLite JSONB: When and How to Use It.
-
json
The SQLitejson()function validates the string specified by the parameter and converts it to a minimal JSON string, with all unnecessary whitespace removed. -
json_array
The SQLitejson_array()function evaluates all the values in the parameters list and returns a JSON array containing all the parameters. -
json_array_length
The SQLitejson_array_length()function returns the length of elements in the specified JSON array, that is the number of the top level child elements in the JSON array. -
json_each
SQLite json_each() returns rows for the immediate children of a JSON object or array; primitive input produces one row. -
json_extract
The SQLitejson_extract()function extracts the value specified by the path expression from the JSON document and returns it. -
json_group_array
The SQLitejson_group_array()function is an aggregate function that returns a JSON array containing all the values in a group. -
json_group_object
The SQLitejson_group_object()function is an aggregate function that returns a JSON object containing the key-value pairs of the specified columns in a group. -
json_insert
The SQLitejson_insert()function inserts values into a JSON document and return a new JSON document. -
json_object
The SQLitejson_object()function returns a JSON object containing all the key-value pairs specified by the parameters. -
json_patch
The SQLite json_patch() function merges and patchs the second JSON object to the original JSON object, and returns the patched original JSON object. -
json_quote
The SQLitejson_quote()function converts the SQL value specified by the parameter to the corresponding JSON representation. -
json_remove
The SQLitejson_remove()function removes the data specified by a path from a JSON document and returns the modified JSON document. -
json_replace
The SQLitejson_replace()function replaces existing data in a JSON document and return modified JSON document. -
json_set
The SQLitejson_set()function inserts or updates data in a JSON document and return the modified JSON document. -
json_tree
Use SQLite json_tree() to recursively query JSON values and inspect each row’s key, value, type, atom, fullkey, and parent. -
json_type
The SQLitejson_type()returns the type of a JSON value or the value of the specified path in JSON document. -
json_valid
The SQLitejson_valid()unction returns 0 or 1 to indicate whether the given parameter is a valid JSON document. -
jsonb
Convert JSON text to SQLite’s binary JSONB BLOB with jsonb(), or pass through an input that appears to be JSONB. -
jsonb_each
Use SQLite jsonb_each() to expand one JSON object or array level, returning nested objects and arrays as JSONB values. -
jsonb_tree
Use SQLite jsonb_tree() to recursively expand JSON, returning nested objects and arrays as JSONB values.