I am struggling with an API that returns a JSON object containing badly formatted values with \r and \n characters. Despite my attempts to use JSON.stringify to convert it into a string and then remove these characters, I still encounter errors when trying to parse the data again.
Response
{
"seller_store_name": "test",
"seller_store_description": "<blockquote>
<p>ewffwewef</p>
<p>wefwef</p>
<p> </p>
<table>
<tbody>
<tr>
<td> </td>
<td> </td>
<td>fewfewf</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td>efwfewf</td>
</tr>
</tbody>
</table>
</blockquote>",
"seller_profile_picture":"",
"seller_profile_picture_default": "https://test.com/",
"seller_banner": "",
"seller_banner_default": "https://test.com/"
}
Attempt 1, turning it into a string and removing unwanted characters
sellerData = JSON.stringify(e);
" {\n \"seller_store_name\": \"test\",\n \"seller_store_description\": \"<blockquote>\r\n<p>ewffwewef</p>\r\n<p>wefwef</p>\r\n<p> </p>\r\n<table>\r\n<tbody>\r\n<tr>\r\n<td> </td>\r\n<td> </td>\r\n<td>fewfewf</td>\r\n</tr>\r\n<tr>\r\n<td> </td>\r\n<td> </td>\r\n<td>efwfewf</td>\r\n</tr>\r\n</tbody>\r\n<table>\r\n</blockquote>\",\n \"seller_profile_picture\":\"\",\n \"seller_profile_picture_default\": \"https://test.com\",\n \"seller_banner\": \"\",\n \"seller_banner_default\": \"https://test.com\"\n }\n "
sellerData = sellerData.replace(/\\r/g,"").replace(/\\n/g,"");
sellerData = JSON.parse(sellerData);
Although this successfully removes the characters, I am unable to turn the data back into an object as it remains a string.
Attempt 2, attempting basic parsing
sellerData = JSON.parse(String(e));
Unexpected token in JSON at position 126
Any assistance would be greatly appreciated. Unfortunately, I do not have the authority to alter the API response.