Well I have the following JSON:
{
"creatorId": "#1",
"data": {
"id": "10",
"creator": "#1"
},
"subs": ["1"]
}
But the content of data must not be an object. But an object in string format.
{
"creatorId": "#1",
"data": "{
\"id\": \"10\",
\"creator\": \"#1\"
}",
"subs": ["1"]
}
All this is because my intention is to collect the data field from the JSON and convert it to a js object.
const dataObj = JSON.parse(recoverJson.data);
And of course the simplest thing would be to pass the object directly to it and not have to collect the string and so on. But it is an API requirement that what arrives is a string.
How could I assemble the JSON with a "strigified" object
I'll put it in several steps to make it clear, but you can save yourself some of the intermediate variables:
Well I was mounting the escape characters wrong. So I have found the solution but programmatically. Following the suggestions in the comments. I have assembled the following code: