SQLite 3 reference · JSON Functions

SQLite JSON_GROUP_OBJECT() Function

Aggregate key/value pairs from the rows of a group into one JSON object, such as a name-to-price lookup.

SQLite 3 Since 3.10.0

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

Syntax

json_group_object(key, value)

Parameters

ParameterDescription
key The key for each row.
value The value for each row.

Return value

JSON object text.

Examples

Build a lookup objectTry it yourself
SELECT json_group_object(name, price) AS prices
FROM products
WHERE category_id = 1;

Output

prices
{"SQL for Beginners":29.99,"Clean Code":37.5,"The Pragmatic Programmer":42.0}
Counts as an objectTry it yourself
SELECT json_group_object(status, n) AS counts
FROM (SELECT status, count(*) AS n FROM orders GROUP BY status);

Output

counts
{"cancelled":1,"delivered":7,"pending":2,"shipped":2}

Version history

VersionChange
SQLite 3.10.0Added

In other languages

Was this page helpful?