reviveNumber

Revive a JSON-serialized number.

Usage

var reviveNumber = require( '@stdlib/number/float64/reviver' );

reviveNumber( key, value )

Revives a JSON-serialized number.

var parseJSON = require( '@stdlib/utils/parse-json' );

var str = '{"type":"float64","value":"NaN"}';

var buf = parseJSON( str, reviveNumber );
// returns NaN

For details on the JSON serialization format, see @stdlib/number/float64/to-json.

Examples

var parseJSON = require( '@stdlib/utils/parse-json' );
var number2json = require( '@stdlib/number/float64/to-json' );
var reviveNumber = require( '@stdlib/number/float64/reviver' );

var str = JSON.stringify( number2json( NaN ) );
console.log( str );
// => '{"type":"float64","value":"NaN"}'

var out = parseJSON( str, reviveNumber );
if ( out instanceof Error ) {
    throw out;
}
console.log( out );
// => NaN
Did you find this page helpful?