-
-
Save agrublev/920765a1ab4a0ea05a47b319fc8ca8a0 to your computer and use it in GitHub Desktop.
REGEX to add quotes to JSON unquoted keys (turns an invalid JSON into a valid one). fix json string
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
const fixJsonStr=str=>str.replace(/(\s*?{\s*?|\s*?,\s*?)(['"])?([a-zA-Z0-9_]+)(['"])?:/g, '$1"$3":'); | |
let zzzz=fixJsonStr(`{ | |
"kettty": "", | |
asds: [], kggk:{}, | |
"ga": 222, | |
"sad": { | |
"zz": 0, | |
"as": false, | |
"gag": [] | |
}, | |
"zztt": false | |
}`); | |
console.log(JSON.parse(zzzz)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment