Safely parsing a JSON string with unquoted keys
data.replace(/([‘”])?([a-zA-Z0-9]+)([‘”])?:/g, ‘”$2″:’); That will replace any single quotes on the parameter name, and add any that are missing.
data.replace(/([‘”])?([a-zA-Z0-9]+)([‘”])?:/g, ‘”$2″:’); That will replace any single quotes on the parameter name, and add any that are missing.
Yes, you need quotation marks. This is to make it simpler and to avoid having to have another escape method for javascript reserved keywords, ie {for:”foo”}.