I have a backend that's sending invalid JSON strings. It escapes vertical tabs as \v which is not valid in JSON and ends up being rejected by the parser.
I am trying to remedy the problem in the frontend JSON decoder:
function fromJson(json) {
if(typeof json === "string") {
var jsonString = json.replace(/\v/g, "\u000B");
return JSON.parse(jsonString)
}
else {
return json
}
}
Expected output: new string with all instances of \v replaced with the unicode line tabulation.
Actual output:
JSON.parse: SyntaxError: Unexpected token v in JSON at position...