select open change scope Open full search

PG.CENTER connects PostgreSQL documentation, reference, and ecosystem knowledge. Maintained by Pigsty.

FUNCTIONS / JSON FUNCTIONS AND OPERATORS

Builds a JSON object out of a text array.

Signatures & examples

jsonb_object ( text[] ) → jsonb
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.
json_object('{a, 1, b, "def", c, 3.5}') → {"a" : "1", "b" : "def", "c" : "3.5"}
json_object('{{a, 1}, {b, "def"}, {c, 3.5}}') → {"a" : "1", "b" : "def", "c" : "3.5"}
jsonb_object ( keys text[], values text[] ) → jsonb
This form of json_object takes keys and values pairwise from separate text arrays. Otherwise it is identical to the one-argument form.
json_object('{a,b}', '{1,2}') → {"a": "1", "b": "2"}
Version history 2
  1. PG 12 → 13changed
  2. PG 9.4 → 9.5added

Definition snapshot: 2026-09-14T13:14:25.684213+00:00@99e6866c · English manual source