bhollis/jsonview

Rendering incorrect data

Closed this issue · 3 comments

I have a couple of cases where json view is rendering data not in the source file.

here is example 1 (_versions.json)

{
    "asset_id": "336541846568177664", 
    "versions": [
        [336541846568177665, "http://aarons-mbp-2011.local/api/assets/336541846568177664/336541846568177665"], 
        [336541849961369600, "http://aarons-mbp-2011.local/api/assets/336541846568177664/336541849961369600"]
    ]
}

When this renders the integer in the fist item in the list is wrong, it's 336541846568177660 see https://dl.dropbox.com/u/11493551/_versions.jpg

This is the item example:

{
    "files": {
        "vulture.jpg": {
            "name": "vulture.jpg", 
            "exif": {}, 
            "tags": [
                "source"
            ]
        }
    }, 
    "updated": {
        "timestamp": "2012-07-17T03:17:08Z", 
        "user": "aaron@foo.com"
    }, 
    "tags": [
        ""
    ], 
    "taxonomy": {}, 
    "related": {}, 
    "id": 336541846568177664, 
    "title": "vulture", 
    "created": {
        "timestamp": "2012-07-17T03:17:08Z", 
        "user": "aaron@foo.com"
    }, 
    "version": 336541846568177665, 
    "storage_app": "reflib", 
    "storage_bucket": "336541846568177666"
}

It renders both the id and version fields as having the value 336541846568177660 see https://dl.dropbox.com/u/11493551/item.jpg

The issue seems to be with handling long integers (the ones that work are strings).

Any thoughts ?

This was brought up on the old issue tracker but didn't get transferred over. Basically, there's a maximum size for integers in JavaScript, and thus in JSON (well, not technically in JSON, but JSONView is written in JavaScript and Firefox's JSON parser is designed for use with JavaScript). Because JavaScript represents all numbers as an IEEE double, it loses precision after a while. Check out http://stackoverflow.com/questions/209869/what-is-the-accepted-way-to-send-64-bit-values-over-json for more info.

Unfortunately, since this is a limitation in JSON (and JSON implementations) itself, I'm not going to be able to fix it in JSONView.

You may also refer to https://www.ietf.org/rfc/rfc4627.txt, section 4 "An implementation may set limits on the range of numbers." I do wish it did so a bit more explicitly than just losing precision.

I thought it was something like that. I did look at the construction of numbers on http://www.json.org/ and saw that the definitions did not specify bounds.

Guess I can just make them strings.
Cheers