Function jsonb_object_2d

Source
fn jsonb_object_2d(array: ListRef<'_>) -> Result<JsonbVal>
Expand description

Builds a JSON object out of a text array.

The array must have either exactly one dimension with an even number of members, in which case they are taken as alternating key/value pairs, or two dimensions such that each inner array has exactly two elements, which are taken as a key/value pair. All values are converted to JSON strings.

ยงExamples

query T
select jsonb_object('{{a, 1}, {b, def}, {c, 3.5}}' :: text[][]);
----
{"a": "1", "b": "def", "c": "3.5"}

# FIXME: `null` should be parsed as a null value instead of a "null" string.
# query error null value not allowed for object key
# select jsonb_object('{{a, 1}, {null, "def"}, {c, 3.5}}' :: text[][]);

query error array must have two columns
select jsonb_object('{{a, 1, 2}, {b, "def"}, {c, 3.5}}' :: text[][]);