Skip to content

Instantly share code, notes, and snippets.

@mladenp
Created July 15, 2016 11:22
Show Gist options
  • Save mladenp/913478fd4418e548cc1a62f5ae10aa26 to your computer and use it in GitHub Desktop.
Save mladenp/913478fd4418e548cc1a62f5ae10aa26 to your computer and use it in GitHub Desktop.
JSON parse escape special 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