18 Apr 2006, 11:00pm
Projects:
by

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 Reply

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

    *

    You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

     

    Recent Posts

    Recent Comments

    • Cliffano Subagio: Good to hear about your opportunity to visit Japan, I’m sure you will have a great...
    • Kayla: I’m going to Japan for two week this summer. Our sister city is Tsubame, Japan and my school has an...
    • poseidonfu: thanks,Very effective
    • anonymous: I really enjoyed both the last lecture and the book. I don’t think that theres anyone that I look up...
    • dioni: The thing I hate about HK is how people shove and push in the queue. Can’t they be civilized?!! I kept...

    Most Commented Posts

    Linkroll