betodealmeida opened a new pull request #4908: Replace NaN/Infinity with null
URL: https://github.com/apache/incubator-superset/pull/4908
 
 
   The Python `json` module will happily encode `NaN` and `±Infinity`:
   
   ```python
   >>> import json
   >>> json.dumps([float('nan'), float('inf'), float('-inf')])
   '[NaN, Infinity, -Infinity]'
   ```
   
   The problem is that **this is not valid JSON**, and the browser will choke 
on the payload when running `JSON.parse` on it:
   
   ```
   > JSON.parse('[NaN, Infinity, -Infinity]');
   Uncaught SyntaxError: Unexpected token N in JSON at position 1
       at JSON.parse (<anonymous>)
       at <anonymous>:1:6
   ```
   
   To fix this, I used the `simplejson` module instead, since it provides an 
argument `ignore_nan` for converting these values to `null` as recommended by 
the JSON spec:
   
   ```python
   >>> import simplejson as json
   >>> json.dumps([float('nan'), float('inf'), float('-inf')], ignore_nan=True)
   '[null, null, null]'
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to