select open change scope Open full search

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

FUNCTIONS / JSON FUNCTIONS AND OPERATORS

json_populate_record

Read PG 18 manual ↗

Expands the top-level JSON object to a row having the composite type of the base argument.

Signatures & examples

json_populate_record ( base anyelement, from_json json ) → anyelement
Expands the top-level JSON object to a row having the composite type of the base argument. The JSON object is scanned for fields whose names match column names of the output row type, and their values are inserted into those columns of the output. (Fields that do not correspond to any output column name are ignored.) In typical use, the value of base is just NULL, which means that any output columns that do not match any object field will be filled with nulls. However, if base isn't NULL then the values it contains will be used for unmatched columns.
select * from json_populate_record(null::myrowtype, '{"a": 1, "b": ["2", "a b"], "c": {"d": 4, "e": "a b c"}, "x": "foo"}') →  a |   b       |      c
---+-----------+-------------
 1 | {2,"a b"} | (4,"a b c")
Version history 3
  1. PG 12 → 13changed
  2. PG 9.3 → 9.4changed
  3. PG 9.2 → 9.3added

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