Skip to content

Instantly share code, notes, and snippets.

@windwp
Created July 18, 2016 01:26
Show Gist options
  • Save windwp/949e5c221c7f4abba3d48a2fe4325ccf to your computer and use it in GitHub Desktop.
Save windwp/949e5c221c7f4abba3d48a2fe4325ccf to your computer and use it in GitHub Desktop.
Json fix for parse
s = s.replace(/\\n/g, "\\n")
.replace(/\\'/g, "\\'")
.replace(/\\"/g, '\\"')
.replace(/\\&/g, "\\&")
.replace(/\\r/g, "\\r")
.replace(/\\t/g, "\\t")
.replace(/\\b/g, "\\b")
.replace(/\\f/g, "\\f");
// remove non-printable and other non-valid JSON chars
s = s.replace(/[\u0000-\u0019]+/g, "");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment