I need to use:
JSON.stringify()
which should be supported by Chrome, Safari, and Firefox. I think IE8 also has support for the JSON object.
You don't need to use conditionals to determine whether to include json2.js or not. Take a look at the source code:
var JSON;
if (!JSON) {
JSON = {};
}
if (typeof JSON.stringify !== 'function') {
JSON.stringify = function (value, replacer, space) {
// Code
}
}
if (typeof JSON.parse !== 'function') {
JSON.parse = function (text, reviver) {
// Code
}
}
What this does is first check to see if JSON already exists as an object. If not, then it creates a new object to house the JSON functions. Then, it checks for a native implementation of .stringify() or .parse() exist. If not, then it creates those functions.
Bottom line: if a native implementation exists, including json2.js will not overwrite the native implementation. Otherwise, it'll add that functionality, so there's no reason you need to use conditionals, unless you are trying to minimize requests.
(It might also be noted that IE10 does not support conditional statements, so I'd recommend against relying on them unless there isn't any alternative.)