Am stuck with applying replace() with regex for broken nested json value. For example, i want to remove doublequote for origin value below.
How to change from this:
{
"type" : "fruitList",
"data" : [{
"fruitName" : "test",
"origin" : "[{"states" : "USA"}]"
}]
}
To this:
{
"type" : "fruitList",
"data" : [{
"fruitName" : "test",
"origin" : [{"states" : "USA"}]
}]
}
You could simply use 2 replace without RegEx:
jsonstring.replace('"[', "[").replace(']"', "]")
Or if you just want to use a single replace with RegEx:
jsonstring.replace(/("\[|\]")/g, match => {
return match === '"[' ? "[" : "]"
})