Resolve JSON is Undefined Error in Internet Explorer

While running JSON code like the one shown below, older browsers like IE7 produces the error - ‘JSON’ is undefined:

JSON code

JSON is undefined

The error occurs while executing the JSON.parse() method by older browsers that have not implemented the JSON object. The solution to this error is to download the json2 library and include it in your script, as shown below:

Json2.js script

The application uses the json2.js library for browsers that haven’t implemented the JSON object yet. After adding the json2.js library, you can now test the application on IE7 and you will get the desired output

image

Note: All the latest browsers like Firefox 3.5+, IE 8+, Chrome, Safari 4+ etc. have built-in JSON capability.

You also want to look at Is my JSON valid?

15 comments:

  1. I get this error on IE8 also.

    ReplyDelete
  2. That could be as you are running IE8 in compatibility mode?

    ReplyDelete
  3. Thanks a lot man. It really helped me out. Many thanks from Argentina =) Have a good day! bye.

    ReplyDelete
  4. Perfect one..
    Thanks a lot..

    ReplyDelete
  5. Awesome man. You saved my life. Thanks (*follow*)

    ReplyDelete
  6. thanks it works for me perfectly

    ReplyDelete
  7. Excellent! Finally I get the Google Maps API in IE7 working! Thanks for sharing.

    ReplyDelete
  8. Oh man. Thanks for this help. You saved my week

    ReplyDelete
  9. Thank you! You solved my problem!

    ReplyDelete
  10. Thanks alot man...it saved my life.

    ReplyDelete
  11. I included json2.js file but json invalid error is given in IE8

    ReplyDelete
  12. Pls give me solution

    ReplyDelete
  13. Thank you very much.
    From INDIA. :)

    ReplyDelete
  14. Thank you ! My application is in IE7 compatabality mode.When iam running locally iam not getting any Error.But in production iam getting.Any reason for this?

    ReplyDelete