dahngeek
1/18/2017 - 10:11 PM

FIX JSON.parse unexpected token, use this function when having a valid JSON but getting an [Unexpected Token]

FIX JSON.parse unexpected token, use this function when having a valid JSON but getting an [Unexpected Token]

function escapeSpecialChars(jsonString) {

    return jsonString.replace(/\n/g, "\\n")
        .replace(/\r/g, "\\r")
        .replace(/\t/g, "\\t")
        .replace(/\f/g, "\\f");

}