Arr/Obj to string?

Hello, I have an operation that returns an arr/obj in this format:

[{"name":"HOSTING - Basic","isDiscount":false,"currency":"EUR","quantity":1,"price":40,"isTaxIncluded":true},{"name":"HOSTING - Premium","isDiscount":false,"currency":"EUR","quantity":1,"price":55,"isTaxIncluded":true}]

Which is perfect but I have to send a JSON POST call with this arr value and is throwing me errors.
How I can convert that to a string? I have tried with JSON.stringify but nothing.

Thanks.

What is your desired output?

You could do this to stringify the objects in the array, but I’m not sure if this is what you’re aiming for:

const arr = [
  {"name":"HOSTING - Basic","isDiscount":false,"currency":"EUR","quantity":1,"price":40,"isTaxIncluded":true},
  {"name":"HOSTING - Premium","isDiscount":false,"currency":"EUR","quantity":1,"price":55,"isTaxIncluded":true}
].map(el => JSON.stringify(el));

console.log(arr);

Logs:

[
  "{\"name\":\"HOSTING - Basic\",\"isDiscount\":false,\"currency\":\"EUR\",\"quantity\":1,\"price\":40,\"isTaxIncluded\":true}",
  "{\"name\":\"HOSTING - Premium\",\"isDiscount\":false,\"currency\":\"EUR\",\"quantity\":1,\"price\":55,\"isTaxIncluded\":true}"
]

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