views:

1675

answers:

1

I have seen references to some browsers natively supporting JSON parsing/serialization of objects safely and efficiently via the window.JSON Object, but details are hard to come by. Can anyone point in the right direction? What are the methods this Object exposes? What browsers is it supported under?

+6  A: 

Internet Explorer 8 and the latest beta of Firefox (to be version 3.5) support native JSON parsing, but that's it, so I wouldn't count on it.

Links:

musicfreak
I know the support is not widespread, but using this method should be a lot faster and safer than eval()ing a string, so I want to use it where it's available. Any idea on support from other browsers?
levik
I didn't say don't use it, I said don't count on it. Definitely check to see if it's available (at this point only IE8 and the few Fx Beta users) and use it if so, but I'm just saying that you shouldn't assume the browser supports it. As of now, those two are the only browsers that support it, and WebKit is working on it right now, so it'll probably be in Google Chrome and Safari sometime soon.
musicfreak
Oh, and on a side note, NEVER eval() JSON strings. Instead, use one of the many JSON parsing libraries available.
musicfreak
Of the "many" libraries available, are they any preferred? Is the one at http://www.json.org/json2.js generally the most used? I noticed references to it in jQuery 1.4 source.
colbeerhey
@colbeerhey: Yeah, that's the one I see most often. You could also steal jQuery's.
musicfreak
http://code.google.com/chrome/extensions/faq.html#faq-dev-07 - Google Chrome supports natively. I don't know how long is it.
MartyIX