views:

53

answers:

2

Is there any JSON parser/stringifier for Javascript that does not add anything to the prototype (like Date.prototype)?

Because my script is going to be used as a third party script, I want to eliminate the conflicts it may cause.

I am not keen on writing my own serializer/desrializer beacuse probably this was done somewhere else, and better.

+1  A: 

As Marcel suggested Crockford's json2.js is nice option. Many modern browsers (Chrome, Firefox) have in-built JSON parser. If you use crockford's json2.js, it will automatically use native implementation if it is present, falling back to javascript implementation otherwise.

Jayesh
As Nimcap said in a comment to my now deleted answer, json2.js adds `Date.prototype.toJSON` and the like (see l. 175 ff.), so this isn't an option; at least not out of the box.
Marcel Korpel
A: 

I had a quick look at the source code of json-sans-eval and it doesn't extend any object. It's only a JSON parser and not a generator, but it's at least something.

Source code is here.

Marcel Korpel