18 Apr 2006, 11:00pm
Projects:
by Cliffano Subagio

2 comments
  • Trailing Comma Within JSON's Array

    I was debugging an AJAXy app which uses JSON as the data format, and it was fine with Firefox but not with Internet Explorer. After further debugging, the culprit turned out to be trailing commas within the data.

    {"foo": {
        "bar": [
            {"id": "1", "url": "http://www.hostA.com"},
            {"id": "2", "url": "http://www.hostB.com"},
    ] }}
    

    theObject.foo.bar.length returns 2 in Firefox, but it returns 3 in Internet Explorer. The solution was obviously to remove the last comma.

    I’m guessing the problem is more to Javascript array.length which is handled differently between browsers.

    Update: HTML comments embedded within what’s supposed to be JSON’s data will be ignored by Firefox, while they will cause failure during eval in Internet Explorer.

    Related Posts:

    18 Mar 2007, 8:17am
    by Mike Jones

    reply

    Thank you thank you thank you… saved me hours of madness :)

    This is invalid JSON. (but it is valid JavaScript expression). If used as JS term then it is correct, but nobody knows which behaviour (IE or FF) is correct one. :(

     
    leave a comment

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    *name

    *e-mail

    web site


    *name

    *e-mail

    web site

    leave a comment


     

    Recent Posts

    Recent Comments

    • Chess Strategizer: This just got bookmarked! “That’s why I always think of Simon Bolivar and remember that...
    • David from getcheaptrainfares.co.uk: Thank you very much for sharing your wonderful tips! That would definitely be a...
    • Natasha: The quote “Find the best in everybody. Just keep waiting no matter how long it takes. No one is all...
    • Alfonzo Donkin: Stumbled upon your website via bing the other day and absolutely think its great. Carry on the great...
    • Cliffano Subagio: Sure thing.

    Most Commented Posts

    Linkroll