Skip to main content

JSON_OBJECT

Returns an object constructed from the arguments provided.

See also:
[SELECT] [DESCRIBE] [JSON_EXTRACT] [ Data Types ]


tip

Use the DESCRIBE statement to locate array or object datatypes which can be used with StackQL JSON functions.

note

If you are using stackql with a postgres SQL backend, use jsonb_build_object in place of json_object: StackQL passes json_object to PostgreSQL unchanged, and the PostgreSQL function of that name takes its keys and values as text arrays.

Syntax​

SELECT JSON_OBJECT(key1, value1, key2, value2, ...)
FROM <multipartIdentifier>;

Arguments​

key1, key2, ...
The labels for the JSON object.

value1, value2, ...
The values corresponding to the labels in the JSON object.

Return Value(s)​

A string representing the well-formed JSON object.


Examples​

Build an array of JSON objects from a column​

SELECT JSON_GROUP_ARRAY(json_object('instance', selfLink)) as instance_links
FROM google.compute.instances
WHERE project = 'stackql-k8s-the-hard-way-demo'
AND zone = 'australia-southeast1-a'
AND name like '%-dev-controller-%';
/* returns a data structure required for a targetPool in GCP */

For more information, see https://sqlite.org/json1.html#jobj