Is it possible convert string from JSON.stringify back to Array?
Asked
Active
Viewed 3.9k times
3
-
1you can use parseJSON if you are using jquery – karthikr May 19 '13 at 18:28
1 Answers
22
JSON.parse is your friend and answer :)
//examples:
JSON.parse('{}'); // {}
JSON.parse('true'); // true
JSON.parse('"foo"'); // "foo"
JSON.parse('[1, 5, "false"]'); // [1, 5, "false"]
JSON.parse('null'); // null

Dory Zidon
- 10,497
- 2
- 25
- 39
-
Beware of browser compatibility issues, as noted on this link: https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/JSON. – Ricardo Souza May 19 '13 at 18:34
-
dude it's talking about ff 3.5, that's like history :) all browsers today support JSON... – Dory Zidon May 19 '13 at 18:43
-
-
2
-
Well... It all dependes on the target audience, but I think it's always better to use a polyfill like [json2](https://github.com/douglascrockford/JSON-js) in case the browser does not support the native APIs. – Ricardo Souza May 19 '13 at 18:58