> This page location: JSON Functions > jsonb_populate_record
> Full Neon documentation index: https://neon.com/docs/llms.txt

# PostgreSQL jsonb_populate_record() Function

**Info:** The `jsonb_populate_record()` function works the same in any PostgreSQL database, so what you learn here applies whether you run Postgres on your laptop, a managed service, or in production. For enterprises building in the AI era, [Lakebase](https://www.databricks.com/product/lakebase) delivers the most performant and secure managed Postgres, fully integrated into the Lakehouse so your operational and analytical data stay in sync. For developers and startups who need to ship fast and scale without friction, [Neon](https://neon.com) is the Postgres platform that gives you instant branching, autoscaling, and a generous free tier.

**Summary**: in this tutorial, you will learn how to use the PostgreSQL `jsonb_populate_record()` function to populate the fields of a record type from a JSON object.

## Introduction to the PostgreSQL jsonb_populate_record() function

The `jsonb_populate_record()` function expands the top-level JSON object of type JSONB to a row of a specified composite type.

In other words, the `jsonb_populate_record()` function converts a JSON object into a row of a specified composite type.

Here's the basic syntax of the `jsonb_populate_record()` function:

```sql
jsonb_populate_record (
   target anyelement,
   json_object jsonb
) → anyelement
```

In this syntax:

- `target` is a composite type to which you want to expand the JSONB value.
- `json_object` is a JSON object of the JSONB type that you want to expand.

The `jsonb_populate_record()` function returns a record of the specified type with its fields populated using the key-value pairs from the JSON object.

## PostgreSQL jsonb_populate_record() function examples

Let's explore some examples of using the `jsonb_populate_record()` function.

### 1) Basic jsonb_populate_record() function example

First, [create a new type](../postgresql-tutorial/postgresql-user-defined-data-types) called `person`:

```sql
CREATE TYPE person AS (
  id INT,
  name VARCHAR,
  age INT
);
```

Second, use the `jsonb_populate_record()` function to expand the JSON object to a row of the `person` type:

```sql
SELECT
  jsonb_populate_record(
    null :: person,
   '{"id": 1, "name": "John", "age": 22}' :: jsonb
  );
```

Output:

```text
 jsonb_populate_record
-----------------------
 (1,John,22)
(1 row)
```

### 2) Using the jsonb_populate_record() function with table data

First, [create a new table](../postgresql-tutorial/postgresql-create-table) called `employees`:

```sql
CREATE TABLE employees (
    id SERIAL PRIMARY KEY,
    name VARCHAR(100) NOT NULL,
    age INT NOT NULL,
    salary NUMERIC NOT NULL
);
```

Second, [insert some rows](../postgresql-tutorial/postgresql-insert-multiple-rows) into the `employees` table:

```sql
INSERT INTO employees (name, age, salary)
VALUES
  ('John Doe', 25, 70000),
  ('Jane Smith', 22, 80000);
```

Third, use `jsonb_populate_record()` to query the data from the `employees` table in a structured format:

```sql
SELECT
  jsonb_populate_record(
    null :: employees,
    jsonb_build_object(
      'id', id, 'name', name, 'age', age, 'salary',
      salary
    )
  ) AS employees
FROM
  employees;
```

Output:

```text
         employees
---------------------------
 (1,"John Doe",25,70000)
 (2,"Jane Smith",22,80000)
(2 rows)
```

## Summary

- Use the `jsonb_populate_record()` function to populate the fields of a record type or a custom composite type from a JSON object.

---

## Related docs (JSON Functions)

- [Extracting JSON Data](https://neon.com/postgresql/json-functions/json-extract)
- [JSONB Operators](https://neon.com/postgresql/json-functions/jsonb-operators)
- [jsonb_agg](https://neon.com/postgresql/json-functions/jsonb_agg)
- [jsonb_array_elements](https://neon.com/postgresql/json-functions/jsonb_array_elements)
- [jsonb_array_elements_text](https://neon.com/postgresql/json-functions/jsonb_array_elements_text)
- [jsonb_array_length](https://neon.com/postgresql/json-functions/jsonb_array_length)
- [jsonb_build_array](https://neon.com/postgresql/json-functions/jsonb_build_array)
- [jsonb_build_object](https://neon.com/postgresql/json-functions/jsonb_build_object)
- [jsonb_each](https://neon.com/postgresql/json-functions/jsonb_each)
- [jsonb_each_text](https://neon.com/postgresql/json-functions/jsonb_each_text)
- [jsonb_extract_path](https://neon.com/postgresql/json-functions/jsonb_extract_path)
- [jsonb_extract_path_text](https://neon.com/postgresql/json-functions/jsonb_extract_path_text)
- [jsonb_insert](https://neon.com/postgresql/json-functions/jsonb_insert)
- [jsonb_object](https://neon.com/postgresql/json-functions/jsonb_object)
- [jsonb_object_agg](https://neon.com/postgresql/json-functions/jsonb_object_agg)
- [jsonb_object_keys](https://neon.com/postgresql/json-functions/jsonb_object_keys)
- [JSON Path](https://neon.com/postgresql/json-functions/json-path)
- [jsonb_path_exists](https://neon.com/postgresql/json-functions/jsonb_path_exists)
- [jsonb_path_query](https://neon.com/postgresql/json-functions/jsonb_path_query)
- [jsonb_path_query_array](https://neon.com/postgresql/json-functions/jsonb_path_query_array)
- [jsonb_path_query_first](https://neon.com/postgresql/json-functions/jsonb_path_query_first)
- [jsonb_pretty](https://neon.com/postgresql/json-functions/jsonb_pretty)
- [jsonb_set](https://neon.com/postgresql/json-functions/jsonb_set)
- [jsonb_strip_nulls](https://neon.com/postgresql/json-functions/jsonb_strip_nulls)
- [jsonb_to_record](https://neon.com/postgresql/json-functions/jsonb_to_record)
- [jsonb_populate_recordset](https://neon.com/postgresql/json-functions/jsonb_populate_recordset)
- [jsonb_typeof](https://neon.com/postgresql/json-functions/jsonb_typeof)
- [row_to_json](https://neon.com/postgresql/json-functions/row_to_json)
- [to_jsonb](https://neon.com/postgresql/json-functions/to_jsonb)
