NaN and Infinity are not valid JSON

JSON has no way to write NaN, Infinity or -Infinity. Here is why, what happens when you try, and what to use instead.

Open the JSON formatter

What the error looks like

Different engines word this differently. You may see any of these:

Why it happens

Example

Invalid
{
  "score": NaN,
  "limit": Infinity
}
Valid
{
  "score": null,
  "limit": null
}

How this tool reports it

The formatter reports each one and offers to replace it with null, which is what JSON.stringify would have written anyway.

Paste your JSON into the formatter to see the exact line and column, or use the validator if you only need to check it.

Worth knowing