Skip to content

Sanely handle Infinity/-Infinity values in JSON using ?_json_infinity=1 #332

@simonw

Description

@simonw

It turns out if you load this CSV using csvs-to-sqlite you get an Infinity value in SQLite:

name,num
sasha,10
terry,Inf
cathy,0.5

csvs-to-sqlite infinity-bug.csv infinity-bug.db

I deployed this using:

datasette publish now infinity-bug.db --name=datasette-infinity-bug --install=datasette-vega

Datasette outputs that as Infinity in the JSON format, which causes JavaScript errors.

Demo

[
    {
        "rowid": 1,
        "name": "sasha",
        "num": 10.0
    },
    {
        "rowid": 2,
        "name": "terry",
        "num": Infinity
    },
    {
        "rowid": 3,
        "name": "cathy",
        "num": 0.5
    }
]

But... in Firefox that gets rendered like this:

2018-06-29 at 4 20 pm

And if you click the "Show charting options" button you get this error in the console:

SyntaxError: JSON.parse: unexpected character at line 1 column 83 of the JSON data

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions