Skip to content

Instantly share code, notes, and snippets.

@Tanapruk
Created March 1, 2019 08:44
Show Gist options
  • Save Tanapruk/4ab1505ead2491229235c886b6fbfaac to your computer and use it in GitHub Desktop.
Save Tanapruk/4ab1505ead2491229235c886b6fbfaac to your computer and use it in GitHub Desktop.
JSON.stringify remove slash double slash
function replacer(key, value) {
if (typeof value === 'string') {
//to avoid ///"
//add space to , and :
return value.replace(/"/g, '').replace(/,/g, ', ').replace(/:/g, ': ')
} else {
return value
}
}
const jsonData = JSON.stringify(data, replacer)
@Tanapruk
Copy link
Author

Tanapruk commented Mar 1, 2019

Simply remove " in the replacer function. When stringify that " won't get escape and /// won't show up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment