I need to save json object with other nested objects into my postgres db. The json I'm receiving from user's browser.
I'm using Postgres 11.5 on AWS RDS. On backend I'm using NodeJS (NestJS/TypeScript/TypeORM).
I tried to convert each item of array to string using JSON.stringigy() but anyway I'm receiving error UnhandledPromiseRejectionWarning: QueryFailedError: malformed array literal: "[{"name":"Oviedo, Asturias, Spain"},{"name":"Oviedo, Asturias, Spain"}]"
Array looks like this:
"waypoints": [
{
"name": "Oviedo, Asturias, Spain"
},
{
"name": "Oviedo, Asturias, Spain"
}
]
This is a field to store the array above
@Column({ type: 'jsonb', array: true })
waypoints: any[];
And I assign data like this:
event.waypoints = eventData.waypoints;
// also I tried to do like this
event.waypoints = JSON.stringify([{ text: 'Some text' }, { text: 'Some text 2' }]);
Right now I'm receiving error:
(node:12833) UnhandledPromiseRejectionWarning: QueryFailedError: malformed array literal: "[{"name":"Oviedo, Asturias, Spain"},{"name":"Oviedo, Asturias, Spain"}]"
at new QueryFailedError (/home/banha/Projects/train-time-server/node_modules/typeorm/error/QueryFailedError.js:11:28)
at Query.callback (/home/banha/Projects/train-time-server/node_modules/typeorm/driver/postgres/PostgresQueryRunner.js:176:38)
at Query.handleError (/home/banha/Projects/train-time-server/node_modules/pg/lib/query.js:142:17)
at Connection.connectedErrorMessageHandler (/home/banha/Projects/train-time-server/node_modules/pg/lib/client.js:211:17)
at Connection.emit (events.js:209:13)
at Connection.EventEmitter.emit (domain.js:476:20)
at Socket.<anonymous> (/home/banha/Projects/train-time-server/node_modules/pg/lib/connection.js:126:12)
at Socket.emit (events.js:209:13)
at Socket.EventEmitter.emit (domain.js:476:20)
at addChunk (_stream_readable.js:305:12)
(node:12833) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:12833) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.