how do i convert javascript into structured jsonb in postgres?

You have wrong syntax :). Postgres is not JavaScript. Postgres json syntax is more closer to Python’s dictionaries (keys need to be quoted). Use double quotes for the keys and string values instead of single quotes. Then use ::jsonb to convert that to proper jsonb format.

JSON.stringify is fine for this purpose, I don’t know why your select is wrong.

Your select should be:

SELECT '{ "name": "amit", "age": 44, "likes": ["some", "things"]}'::jsonb;

console.log(JSON.stringify({ name: 'amit', age: 44, likes: ['some', 'things']}));

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top