json_group_object
Collects name/value pairs into a JSON text object. Missing values become JSON
null; duplicate names are retained.
Syntax
text
json_group_object(name, value [ORDER BY expression])Arguments
name— A non-NULLobject key. Other SQL values are converted to text. ANULLkey raises an error.value— A SQL value. Text is quoted as a JSON string;json(value)parses text before including it as a structured value. Binary blobs are rejected.
FILTER, aggregate ordering, and ordinary window calls are supported.
Returned value
A JSON text object. Empty input returns {}.
Examples
sql
CREATE TABLE attributes (name String, value Int32);
INSERT INTO attributes VALUES ('available', 12), ('reserved', NULL);sql
SELECT json_group_object(name, value ORDER BY name)
FROM attributes
FORMAT csv;text
"{""available"":12,""reserved"":null}"sql
SELECT json_group_object(name, value)
FROM attributes
WHERE value > 100
FORMAT csv;text
"{}"