Created
March 26, 2021 09:55
-
-
Save CostasAK/ec8d3a4b562e03dd578ff46b0713fba4 to your computer and use it in GitHub Desktop.
Iterate through a nested object and replace reserved JSON characters.
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
| const iterate = (obj) => { | |
| Object.keys(obj).forEach(key => { | |
| if (typeof obj[key] === 'object') { | |
| iterate(obj[key]) | |
| } else if (typeof obj[key] === 'string' || obj[key] instanceof String) { | |
| obj[key] = obj[key].replace(/\n/g,'\\u000a').replace(/"/g,'\\u0022').replace(/'/g,'\\u0027'); | |
| } | |
| }) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment