stdlib icon indicating copy to clipboard operation
stdlib copied to clipboard

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

Open kgryte opened this issue 3 years ago • 0 comments

Description

This RFC proposes add support for serializing positive and negative Infinity to JSON.

Currently, when serializing an object containing an Infinity (either positive or negative), the resultant value is null.

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

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

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

and proposes to serialize an infinite value as follows:

{
    'type': 'float64',
    'value': '+Infinity'
}
{
    'type': 'float64',
    'value': '-Infinity'
}

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

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

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 02:09 kgryte