I realize that the topic of converting Javascript to JSON and escaping correctly has been covered (for instance here, Convert JS object to JSON string, and here, How can I accommodate a string with both single and double quotes inside of it in Javascript). I'm not having much success at all, though --
I'm trying to pass a large Javascript object to a POST call (using Postman) that asks me to pass it in the following manner:
{
"key":"/url/url/es", "value":"{myData}"
}
Where my object needs to fill the part of {myData}
. My data structure is too large to pass here entirely, but it contains parts like this
name: 'Something',
reactComponentName: 'EntradaTwoPack',
numberOfCards: 2,
variant: '0',
mainTitle: 'Something',
cards: [
{
name: 'card1',
elements: {
showImage1: false,
_comment: 'These fields are required, the component can expect them to know what to paint',
},
values: {
cardTitle: '1 DÍA 1 PARQUE',
cardLinkText: 'Condiciones',
cardLinkURL: '/condiciones',
images: ['https://s3-eu-west-1.amazonaws.com/anImage.png'],
section0Title: 'Adulto',
section0SubTitle: '11 - 59 años',
section1Title: 'Júnior / Sénior',
section1SubTitle: '4 - 10 años/+60 años',
},
]
That is, it contains single quotes, URLs, objects inside arrays, objects in objects, etc. I've tried escaping the single quotes and the forward slashes in the URLs, removing the line breaks, etc, but nothing seems to work. (I end up with an output that resembles this:
mainTitle: \'TOP HOTELES\', mainDescription: \'Lorem ipsum dolor sit amet, consectetur adipiscing elit. \', mainLinkURL: \'http:\/\/www.startpage.com\', showBreadCrumb: false, cards: [ { name: \'card1\',
I've pasted it in the console of Chrome and then I JSON.stringify()
it, but that didn't work either. I've also taken the output from Chrome and escaped it, as per above, but no dice. Perhaps I'm missing something conceptually -- any advice welcome!