SQLite 3 reference · JSON Functions

SQLite JSON_OBJECT() Function

Build a JSON object from key and value pairs. SQL NULL becomes JSON null; nested json() values stay JSON.

SQLite 3 Since 3.9.0

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

json_object(key1, value1, ...)

Parameters

ParameterDescription
key, value Pairs of a text key and a value.

Return value

JSON object text.

Examples

Rows as JSON objectsTry it yourself
SELECT json_object('id', customer_id, 'name', name, 'email', email) AS customer
FROM customers
WHERE customer_id IN (4, 5);

Output

customer
{"id":4,"name":"Linus Torvalds","email":"[email protected]"}
{"id":5,"name":"Margaret Hamilton","email":null}
Nested JSON vs plain textTry it yourself
SELECT json_object('tags', json_array('a', 'b'), 'raw', '[1,2]') AS mixed;

Output

mixed
{"tags":["a","b"],"raw":"[1,2]"}

Version history

VersionChange
SQLite 3.9.0Added
SQLite 3.38.0Built in by default; earlier versions needed the JSON1 extension.

In other languages

Was this page helpful?