Q:

Json data containing NaN results in error during ajax request

I an endpoint exposed via web api which spews out JSON like this:
"[{"SomeId":1,"SomeName":"Some name 1","Parameter1":1.13,"Parameter2":3.0 ...

to jquery ajax get requests. Everything works fine until the JSON contains NaN (not a number):
"[{"SomeId":1,"SomeName":"Some name 1","Parameter1":1.13,"Parameter2":NaN ...

If this type of data is returned the error callback is hit.
Is this a known issue? Is jquery or web api to blame? How can I mitigate this? Thanks.

A:

This happens because the token NaN is invalid in JSON. JSON is a subset of JavaScript's object initializer syntax, which doesn't include several aspects of it, including NaN (and Infinity, undefined, ...).
The web API providing that output is producing invalid JSON, so any conforming JSON parser will complain about it. You'll need to fix (or ask the providers of it to fix) the API.

