Insert record to table with jsonb column

I have a table in postgres with some jsonb columns.

create table example (
  "id" serial,
  "name" text,
   "location" jsonb,
   "account_info" jsonb,
   "age" int
)

I query a rest api to fetch the data to insert into the table. Example response from rest api call;

[{
"id": 1,
"name": "Jackson",
"location": {"lat":0.308473, "lon":94.203948},
"account_info":{"bank":"Chase","number":"289483724"},
"age":27
},{
"id": 1,
"name": "Jackson",
"location": {"lat":0.308473, "lon":94.203948},
"account_info":{"bank":"Chase","number":"289483724"},
"age":27
}]

I have a separate query that calls the api and returns the data in {{query.data}}

The issue I am having is that retool keeps saying "invalid input syntax for type json". How do I handle this?

It looks like you need to stringify it with JSON.stringify(query.data). You can alsocheck with JSON.parse(query.data) and seeing if JS returns an error.

2 Likes

Sorry the bug was from my code :man_facepalming:

Yeah, this definitely works. Thanks @DoingMyBest

2 Likes