Data is null when Json contains NaN
See original GitHub issueWhen 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):
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:
- Created 6 years ago
- Reactions:1
- Comments:5
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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
That’s a bummer. Thanks for your help anyways 😃