How to I parse var string = "{email: [email protected]}" into an object?
I've tried var object = JSON.parse(string); which returns an error
Uncaught SyntaxError: Unexpected token e(…)
And var object eval('(' + string + ')'); can't handle '@'.
JSON.parseisn't working because theemailkey and the corresponding value need to be strings in order to be valid JSON. If you're just learning JSON, or don't quite have a full grasp on the syntax, try running it through JSONLint, it'll point out errors for you.var string = "{'email': '[email protected]'}"?var string = "{\"email\": \"[email protected]\"}"var text = JSON.stringify("{" + key + ": " + value + "}");