You can choose one of the following methods:
<script>window.JSON || document.write('<script src="js/json2.js"><\/script>')</script>
This checks for window.JSON
(supported by the browser) if it exists, use this, otherwise it imports json2.js from Crockford.
Update
var whichJSON = null; if (! window.JSON) { document.write('<script src="js/json2.js"><\/script>'); whichJSON = 'Crockford Version'; } else { whichJSON = 'Browser Native Version'; } alert(whichJSON);
source share