Skip to main content

JSON_OBJECT

Returns an object constructred from arguments provided.

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


tip

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

note

The json_object function as jsonb_build_object if you are using stackql with a postgres SQL backend.

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

Return the datatype of a field nested within a JSON object or array

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