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

1 comment
  • 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.

     
     

    Recent Posts

    Recent Comments

    • Tharindu: i started blogging long long time back but couldnt continue. last november i stated blogging again with...
    • maria: maybe he didnt believe in god, i dont either and does it really matter?? his message is the same:he talks...
    • Cliffano Subagio: Sure thing. The license for the images is Creative Commons Attribution Share Alike...
    • daniel: nice articles. can I copy your images? :D
    • Cliffano Subagio: Only an idea, won’t be made into real site (unless someone else wants to do it). Something...

    Most Commented Posts

    Linkroll