stdlib icon indicating copy to clipboard operation
stdlib copied to clipboard

[RFC]: add support for serializing `NaN` to JSON

Open kgryte opened this issue 3 years ago • 0 comments

Description

This RFC proposes add support for serializing NaN to JSON.

Currently, when serializing an object containing a NaN, the resultant value is null.

In [1]: JSON.stringify( { 'x': NaN } )
Out[1]: '{"x":null}'

This is problematic when attempting to roundtrip an object data structure containing NaN values.

This RFC seeks to remedy this problem by standardizing how NaN values are serialized to JSON. This proposal builds on

and proposes to serialize a NaN value as follows:

{
    'type': 'float64',
    'value': 'NaN'
}

A corresponding JSON reviver (e.g., similar to @stdlib/buffer/reviver) can then recognize the standardization format and reconstitute a NaN value.

Package: @stdlib/number/float64/nan2json Alias: nan2json

Related Issues

No.

Questions

No.

Other

No.

Checklist

  • [X] I have read and understood the Code of Conduct.
  • [X] Searched for existing issues and pull requests.
  • [X] The issue name begins with RFC:.

kgryte avatar Sep 09 '22 01:09 kgryte