# Issue inserting json array into postgres jsonb column

**URL:** <https://community.n8n.io/t/issue-inserting-json-array-into-postgres-jsonb-column/79810>\
**Category:** Questions\
**Tags:** postgres, ai-kapa\
**Created:** [February 20, 2025, 4:10am UTC](https://community.n8n.io/t/issue-inserting-json-array-into-postgres-jsonb-column/79810 "2025-02-20T04:10:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matthew\_Bussmann](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/matthew_bussmann/32/59210_2.png) [@Matthew\_Bussmann](https://community.n8n.io/u/Matthew_Bussmann)\
**Post date:** [February 20, 2025, 4:10am UTC](https://community.n8n.io/t/issue-inserting-json-array-into-postgres-jsonb-column/79810/1 "2025-02-20T04:10:03Z")

</div>

## Describe the problem/error/question

I’m trying to store some response data into a Postgres Table. I’ve got a few fields where some of the types are arrays (empty or not empty):

```auto
{"field_1" : [], "field_2": [] }

```

I was originally attempting to store these data using `jsonb`, but it appears that when mapping the fields from the response JSON to the postgres insert node, I’m getting an error that an Object is expected and not an array.

I attempted to do a workaround I found here that says using `JSON.stringify()` on the object is supposed to help, but that did not work.

I’ve also tried changing the postgres column datatype to `jsonb[]`. Again, same issue.

I feel as though this is a valid means to set the data type into postgres jsonb, so I’m unsure why this is throwing an error. Any help would be much appreciated.

## What is the error message (if any)?

**Invalid input for ‘mentions’ [item 0]**

**‘mentions’ expects a object but we got array**

## Please share your workflow

I’m going to hold off until I figure how to keep some PII off this.

## Share the output returned by the last node

## Information on your n8n setup

- \*\*n8n version:_1.75.2_
- **Database (default: SQLite):**
- **n8n EXECUTIONS\_PROCESS setting (default: own, main):**
- \*\*Running n8n via (Docker, npm, n8n cloud, desktop app):_Docker_
- **Operating system:**

---

<div class="post-metadata">

**Author:** ![solomon](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/solomon/32/43567_2.png) [@solomon](https://community.n8n.io/u/solomon)\
**Post date:** [March 4, 2025, 3:51pm UTC](https://community.n8n.io/t/issue-inserting-json-array-into-postgres-jsonb-column/79810/3 "2025-03-04T15:51:53Z")

</div>

If you’re going to send an empty array, try using `null` instead. See if that works.

Make sure your column is configured to accept null values.

---

<div class="post-metadata">

**Author:** ![Matthew\_Bussmann](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/matthew_bussmann/32/59210_2.png) [@Matthew\_Bussmann](https://community.n8n.io/u/Matthew_Bussmann)\
**Post date:** [March 7, 2025, 5:58am UTC](https://community.n8n.io/t/issue-inserting-json-array-into-postgres-jsonb-column/79810/4 "2025-03-07T05:58:58Z")

</div>

Hey thanks for the reply! So after some more testing… null works fine. I used a Set Node to conditionally set all the length === 0 arrays to null and that worked with no issues.

Seems like now that the issues is that the Postgres JSONB type wants an object. I’ve tried to send both the array empty as well as Stringify the array. The only other thing I could mabye do is set the array as the field in an object, so something like `{"field1": [] }` → `{ "field1": { "field1" : [] } }`… which feels incredibly silly to have to do.

Any thoughts?

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/system/32/36532_2.png) [@system](https://community.n8n.io/u/system)\
**Post date:** [June 5, 2025, 5:58am UTC](https://community.n8n.io/t/issue-inserting-json-array-into-postgres-jsonb-column/79810/5 "2025-06-05T05:58:59Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
