Created
March 1, 2019 08:44
-
-
Save Tanapruk/4ab1505ead2491229235c886b6fbfaac to your computer and use it in GitHub Desktop.
JSON.stringify remove slash double slash
This file contains 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 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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Simply remove " in the replacer function. When stringify that " won't get escape and /// won't show up.