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

# PostgreSQL jsonb_object() Function

**Info:** The jsonb_object() function works the same across every PostgreSQL deployment, so what you learn here carries over no matter where you run Postgres. For enterprises building in the AI era, [Lakebase](https://www.databricks.com/product/lakebase) delivers the best managed cloud Postgres, with the performance, security, and native Lakehouse integration that serious data teams expect. For developers and startups who need to ship features and scale without friction, [Neon](https://neon.com) is the Postgres platform built to move at your speed.

**Summary**: in this tutorial, you will learn how to use the PostgreSQL `jsonb_object()` function to create a JSON object from a text array.

## Introduction to the PostgreSQL jsonb_object() function

The `jsonb_object()` function allows you to build a JSON object from a [text](../postgresql-tutorial/postgresql-char-varchar-text) [array](../postgresql-tutorial/postgresql-array).

Here's the syntax of the `jsonb_object()` function:

```sql
jsonb_object(text[]) → jsonb
```

In this syntax, `text[]` array can be:

- A one-dimensional array that contains an even number of elements. The elements are the alternating key/value pairs.
- A two-dimensional array. Each inner array has exactly two elements representing the key/value pair.

The `jsonb_object()` function returns a JSON object constructed from the text array with the type of JSONB.

The `jsonb_object()` function has another syntax that takes keys and values pairwise from separate text arrays:

```sql
jsonb_object ( keys text[], values text[] ) → jsonb
```

In this syntax, the keys and values arrays in this syntax have the same number of elements. The `keys` array contains the keys of the JSON object whereas the `values` array contains the corresponding values of the `keys`.

## PostgreSQL jsonb_object() function examples

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

### 1) Basic PostgreSQL jsonb_object function examples

The following example uses the `jsonb_object()` function to create a JSON object from a text array:

```sql
SELECT
  jsonb_object('{"name","John", "age", 22}');
```

Output:

```text
         jsonb_object
-------------------------------
 {"age": "22", "name": "John"}
(1 row)
```

Alternatively, you can use a two-dimensional arrays to create the JSON object:

```sql
SELECT
  jsonb_object(
    '{{"name","age"},{"John", 22}}'
  );
```

Output:

```text
         jsonb_object
-------------------------------
 {"John": "22", "name": "age"}
(1 row)
```

Additionally, you can use two arrays including `keys` and `values` to create the JSON object:

```sql
SELECT
  jsonb_object(
    '{"name","age"}', '{"John", 22}'
  );
```

Output:

```text
         jsonb_object
-------------------------------
 {"age": "22", "name": "John"}
(1 row)
```

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

We'll use the `film` table from the [sample database](../postgresql-getting-started/postgresql-sample-database).

![](https://neon.com/postgresqltutorial/film.png)The following example uses the `jsonb_object` function to create an object from the `title` and `release_year` from the `film` table:

```sql
SELECT
  jsonb_object(
    array[title], array[release_year]::text[]
  )
FROM
  film
ORDER BY
  title;
```

Output:

```text
         jsonb_object
------------------------------
 {"Academy Dinosaur": "2006"}
 {"Ace Goldfinger": "2006"}
 {"Adaptation Holes": "2006"}
 {"Affair Prejudice": "2006"}
 {"African Egg": "2006"}
...
```

## Summary

- Use the PostgreSQL `jsonb_object()` function to create a JSON object from a text array.

---

## 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_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_record](https://neon.com/postgresql/json-functions/jsonb_populate_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)
