Created
July 15, 2016 11:22
-
-
Save mladenp/913478fd4418e548cc1a62f5ae10aa26 to your computer and use it in GitHub Desktop.
JSON parse escape special characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function escapeSpecialChars(jsonString) { | |
return jsonString.replace(/\n/g, "\\n") | |
.replace(/\r/g, "\\r") | |
.replace(/\t/g, "\\t") | |
.replace(/\f/g, "\\f"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment