Skip to content

Instantly share code, notes, and snippets.

@adamgruber
Last active May 12, 2017 13:56
Show Gist options
  • Save adamgruber/1519e73a9c95399fcac439b59d77d43a to your computer and use it in GitHub Desktop.
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
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