i have an object that is coming from the third party api. and it is in the form like this :
"{ "type": "object", "properties": { "hostUrl": { "type": "string", "description": "hostUrl", }, }, }"
due to the double quote in the start and the end i am getting error and json parse is also not being removed so kindly tell me how to remove this double quote which has wrapped my object inside it
Advertisement
Answer
try this
const jsonStr = '"{ "type": "object", "properties": { "hostUrl": { "type": "string", "description": "hostUrl", }, }, }"'; var json = jsonStr .substring(1, jsonStr.length - 1) .replaceAll("},", "}") .replaceAll(" ", "") .replaceAll(",}", "}");
json
{ "type": "object", "properties": { "hostUrl": { "type": "string", "description": "hostUrl" } } }