tags:

views:

7494

answers:

3

Can someone tell me what the difference is between the 2 json files?

http://www.json.org/json.js

http://www.json.org/json2.js

I have a JSON file from 2007-04-13 (It has methods such as parseJSON). I don't see these methods in any of the new versions.

+6  A: 

From their code:

// Augment the basic prototypes if they have not already been augmented.
// These forms are obsolete. It is recommended that JSON.stringify and
// JSON.parse be used instead.

if (!Object.prototype.toJSONString) {
    Object.prototype.toJSONString = function (filter) {
        return JSON.stringify(this, filter);
    };
    Object.prototype.parseJSON = function (filter) {
        return JSON.parse(this, filter);
    };
}

I guess parseJSON is absolete, therefore the new version (json2) doesn't even use it anymore. However if your code uses parseJSON a lot you could just add this piece of code somewhere to make it work again:

    Object.prototype.parseJSON = function (filter) {
        return JSON.parse(this, filter);
    };
Luca Matteis
Thanks, so it appears that parseJSON has been replaced by JSON.parse?Also, what about toJSONString? Our existing code uses a lot of these methods: boolean.toJSONString() date.toJSONString() number.toJSONString() object.toJSONString() string.toJSONString()
Then also add the 1st piece of code, all the values you specified are Objects, therefore they will all be converted to use JSON.stringify automatically.
Luca Matteis
Thanks! I will give this a try. So, can I add these functions to the json.js file?
+5  A: 

Quoting here:

"JSON2.js - Late last year Crockford quietly released a new version of his JSON API that replaced his existing API. The important difference was that it used a single base object."

paxdiablo
A: 

How would you use json2.js. I am trying to call a remote json service. What would be the steps to make to do this? How would I call the JSON service, how would I use the JSON2.js and what is the Javascript I would use to tie all of this together?

carlos
This needs to be a separate question.
Lawrence Johnston