-
-
Save obonyojimmy/8b7ca6c248d4e622585da8ff90017fb1 to your computer and use it in GitHub Desktop.
JavaScript: Sanitize JSON string before saving, so it can be read again. (Escapes newlines etc)
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 sanitizeJSON(unsanitized){ | |
return unsanitized.replace(/\\/g, "\\\\").replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/\t/g, "\\t").replace(/\f/g, "\\f").replace(/"/g,"\\\"").replace(/'/g,"\\\'").replace(/\&/g, "\\&"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment