156

For example, a HTTP REST API just returned me a JSON, but of course it's a string right now. How can I turn it into a JSON?

TIMEX
  • 238,746
  • 336
  • 750
  • 1,061
  • 4
    If you have fixed your problem please accept one of the answers below. If not, let us know whats wrong and we can try to help. – Olical Apr 27 '11 at 09:31
  • 9
    It's not called "a JSON." JSON is a string format. You want to turn a JSON-formatted string into a JavaScript object. Read this for more details: http://benalman.com/news/2010/03/theres-no-such-thing-as-a-json/ – Matt Ball Apr 27 '11 at 13:29

2 Answers2

335

You need to use this function.

JSON.parse(yourJsonString);

And it will return the object / array that was contained within the string.

Olical
  • 36,487
  • 11
  • 54
  • 76
45

use the JSON function >

JSON.parse(theString)
Deepak Mahakale
  • 21,125
  • 10
  • 62
  • 79
neebz
  • 11,249
  • 7
  • 46
  • 62