Convert Array to JSON to store in Database

Ive got an array id like to store in my Database, Ive read JSON files can be stored so how do i go about converting it, Is it as simple as a JSON.stringify(urls) then Update ?
here is my code!

wixData.get(“Members”, userId)
.then((results) => {
item = results; //see item below
console.log(results);
item.links = JSON.stringify(urls);
console.log(item);
}).then((item) => {
wixData.update(“Members”, item)
.then((results) => {
console.log(results);
})
.catch((err) => {
console.log(err);
});
})
.catch((err) => {
let errorMsg = err;
console.log(errorMsg)
});

The Error i receive is
Error: Failed to save [undefined] into [Members].
Items must be JavaScript objects.
at s (all.min.js:1)
at u (all.min.js:1)
at all.min.js:2
at Array.forEach ()
at all.min.js:2
at

Hay Josh,

The problem you see is that in the second .then((item) => function, you get undefined value for the item.

The reason is how promises work - the return value of one is the input value of the next.

Your first function - the following one - does not return anything, so in fact it returns undefined.

		.then((results) => {
			item = results; //see item below
			console.log(results);
			item.links = JSON.stringify(urls);
			console.log(item);
                })

The fix is quite simple - just return the item

		.then((results) => {
			item = results; //see item below
			console.log(results);
			item.links = JSON.stringify(urls);
			console.log(item);
			return item;
                })

Thanks for getting back to me mate, Im finally getting to grips with Wix Code. Worked perfectly, Cheers!