'Remove escaped character in nodejs

I have extracted data into JSON dump / JSON format. Its a huge data of more than 90,000 lines in it. When I extracted, some characters are escaped and replaced. for example " is replaced by \".

I want to remove \r completely and replace \" to "

I dont want to use .replace method of javascript. Can anyone help me to replace the escaped characters \" and \r to their original form. I have tried JSON.parse and .replace methods but it seems to be not working.

Please if anyone have idea to replace them in nodejs, it would be really helpful. Thanks

one line from the json file:

{"time": "10:00", "date": "30-04-2022", "value": "{\"number\":\"1\", \"data\": {\"score\": \"5\", \"team\": "\abc"\}}\r}

expected outcome: {"time": "10:00", "date": "30-04-2022", "value": "{"number":"1", "data": {"score": "5", "team": "abc"}}\r}



Solution 1:[1]

JavaScript replace function only removes the first intersecting substring from the Value

You can use the following code to replace each substring:

function replaceAll(Value, subString, Target) {
    let result = Value;
    while(result.includes(subString)) {
        result.replace(subString, Target);
    }

    return result;
}

I really don't know if you are replacing that text in runtime but you can actually use ctrl + h and replace every substring,

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Tyler2P