Last active
May 12, 2017 13:56
-
-
Save adamgruber/1519e73a9c95399fcac439b59d77d43a to your computer and use it in GitHub Desktop.
Convert a JSON.stringified string to a regular JS object with single-quotes
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 jsonToJs(jsonStr) { | |
return jsonStr | |
.replace(/^(\s+)"(\w+\b)"/g, "$1$2") | |
.replace(/"(.+)"(,?$)/g, "'$1'$2"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment