@stdlib/buffer-to-json
v0.2.2
Published
Return a JSON representation of a Buffer.
Downloads
17
Readme
buffer2json
Installation
npm install @stdlib/buffer-to-json
Usage
var buffer2json = require( '@stdlib/buffer-to-json' );
buffer2json( buffer )
Returns a JSON representation of a Buffer
.
var array2buffer = require( '@stdlib/buffer-from-array' );
var buf = array2buffer( [ 1, 2 ] );
var json = buffer2json( buf );
/* returns
{
'type': 'Buffer',
'data': [ 1, 2 ]
}
*/
For guidance on reviving a JSON-serialized Buffer
, see reviver()
.
Examples
var allocUnsafe = require( '@stdlib/buffer-alloc-unsafe' );
var randi = require( '@stdlib/random-base-discrete-uniform' );
var buffer2json = require( '@stdlib/buffer-to-json' );
var buf = allocUnsafe( 100 );
var i;
for ( i = 0; i < buf.length; i++ ) {
buf[ i ] = randi( 0, 255 );
}
console.log( buffer2json( buf ) );
See Also
@stdlib/array-to-json
: return a JSON representation of a typed array.@stdlib/buffer-reviver
: revive a JSON-serialized Buffer.
Notice
This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.
Community
License
See LICENSE.
Copyright
Copyright © 2016-2024. The Stdlib Authors.