question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Data is null when Json contains NaN

See original GitHub issue

When a response object has a NaN value in it, axios silently fails and gives a response object with data: null.

We understand that NaN, Infinity, and -Infinity aren’t allowed by json, but if that’s the case then the library should throw an error saying that the response can’t be processed. We just found this bug after a lot of very annoying and mysterious debugging, and it would have been nice to understand right away what the problem was.

Here is a screenshot of the request that failed (sensitive information has been redacted): screenshot from 2018-03-12 13-29-43_redacted

and here’s the shortened response text:

[
    {
        "id": 3,
        "date_created": "2018-03-12T17:49:16.260937",
        "date_updated": "2018-03-12T17:49:16.260937",
        "current_value": NaN
    }
]

It’s interesting to note that the chrome devtools understand and parse this response.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:5

github_iconTop GitHub Comments

1reaction
Axnyffcommented, Mar 12, 2018

It looks like it’s the regular behavior of the browser: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/responseType

var a = new XMLHttpRequest(); a.open(‘GET’, ‘/yolo.json?’); a.responseType = ‘json’; a.send()

axios does nothing, it’s the browser which just fails silently

0reactions
bhansenmdcommented, Mar 12, 2018

That’s a bummer. Thanks for your help anyways 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

python - sending NaN in json - Stack Overflow
NaN is not valid JSON, and the ignore_nan flag will handle correctly all NaN to null conversions. import simplejson as json json.dumps(thing, ...
Read more >
json.dumps() should encode float number NaN to null
Float numbers in Python can have 3 special number: nan, inf, -inf, which are encoded by json module as "NaN", "Infinity", "-Infinity".
Read more >
JSON: How to create an undefined or NaN value? - dbj( org )
ECMA zealots argue: “Undefined is null but its identity is not null!”. Sane people (still left) reply: “null is not undefined and undefined...
Read more >
Handling JSON null and empty arrays and objects - IBM
JSON has a special value called null which can be set on any type of data including arrays, objects, number and boolean types....
Read more >
JSON, null and NA
Where this mechanism breaks down is when we have multiple null values in our JSON content and they map to different R values,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found