Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork0
Return a JSON representation of a typed array.
License
stdlib-js/array-to-json
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
About stdlib...
We believe in a future in which the web is a preferred environment for numerical computation. To help realize this future, we've built stdlib. stdlib is a standard library, with an emphasis on numerical and scientific computation, written in JavaScript (and C) for execution in browsers and in Node.js.
The library is fully decomposable, being architected in such a way that you can swap out and mix and match APIs and functionality to cater to your exact preferences and use cases.
When you use stdlib, you can be absolutely certain that you are using the most thorough, rigorous, well-written, studied, documented, tested, measured, and high-quality code out there.
To join us in bringing numerical computing to the web, get started by checking us out onGitHub, and please considerfinancially supporting stdlib. We greatly appreciate your continued support!
Return aJSON representation of a typed array.
To use in Observable,
typedarray2json=require('https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@umd/browser.js')
To vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:
vartypedarray2json=require('path/to/vendor/umd/array-to-json/index.js')
To include the bundle in a webpage,
<scripttype="text/javascript"src="https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@umd/browser.js"></script>
If no recognized module system is present, access bundle contents via the global scope:
<scripttype="text/javascript">(function(){window.typedarray2json;})();</script>
Returns aJSON representation of a typed array.
varFloat64Array=require('@stdlib/array-float64');vararr=newFloat64Array([5.0,3.0]);varjson=typedarray2json(arr);/* returns { 'type': 'Float64Array', 'data': [ 5.0, 3.0 ] }*/
For guidance on reviving a JSON-serialized typed array, seereviver().
Supported typed array types:
The implementation provides basic support for custom typed arrays and sets the
typefield to the closest known typed array type.classCustomArrayextendsFloat64Array(){constructor(data){super(data);}}vararr=newCustomArray([5.0,3.0]);varjson=typedarray2json(arr);/* returns { 'type': 'Float64Array', 'data': [ 5.0, 3.0 ] }*/
<!DOCTYPE html><htmllang="en"><body><scripttype="text/javascript"src="https://cdn.jsdelivr.net/gh/stdlib-js/array-float64@umd/browser.js"></script><scripttype="text/javascript"src="https://cdn.jsdelivr.net/gh/stdlib-js/array-float32@umd/browser.js"></script><scripttype="text/javascript"src="https://cdn.jsdelivr.net/gh/stdlib-js/array-int32@umd/browser.js"></script><scripttype="text/javascript"src="https://cdn.jsdelivr.net/gh/stdlib-js/array-uint32@umd/browser.js"></script><scripttype="text/javascript"src="https://cdn.jsdelivr.net/gh/stdlib-js/array-int16@umd/browser.js"></script><scripttype="text/javascript"src="https://cdn.jsdelivr.net/gh/stdlib-js/array-uint16@umd/browser.js"></script><scripttype="text/javascript"src="https://cdn.jsdelivr.net/gh/stdlib-js/array-int8@umd/browser.js"></script><scripttype="text/javascript"src="https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@umd/browser.js"></script><scripttype="text/javascript"src="https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8c@umd/browser.js"></script><scripttype="text/javascript"src="https://cdn.jsdelivr.net/gh/stdlib-js/array-complex64@umd/browser.js"></script><scripttype="text/javascript"src="https://cdn.jsdelivr.net/gh/stdlib-js/array-complex128@umd/browser.js"></script><scripttype="text/javascript"src="https://cdn.jsdelivr.net/gh/stdlib-js/array-bool@umd/browser.js"></script><scripttype="text/javascript"src="https://cdn.jsdelivr.net/gh/stdlib-js/array-to-json@umd/browser.js"></script><scripttype="text/javascript">(function(){vararr=newFloat64Array([5.0,3.0]);varjson=typedarray2json(arr);/* returns { 'type': 'Float64Array', 'data': [ 5.0, 3.0 ] }*/arr=newFloat32Array([5.0,-3.0]);json=typedarray2json(arr);/* returns { 'type': 'Float32Array', 'data': [ 5.0, -3.0 ] }*/arr=newComplex128Array([5.0,3.0]);json=typedarray2json(arr);/* returns { 'type': 'Complex128Array', 'data': [ 5.0, 3.0 ] }*/arr=newComplex64Array([5.0,3.0]);json=typedarray2json(arr);/* returns { 'type': 'Complex64Array', 'data': [ 5.0, 3.0 ] }*/arr=newBooleanArray([true,false]);json=typedarray2json(arr);/* returns { 'type': 'BooleanArray', 'data': [ 1, 0 ] }*/arr=newInt32Array([-5,3]);json=typedarray2json(arr);/* returns { 'type': 'Int32Array', 'data': [ -5, 3 ] }*/arr=newUint32Array([5,3]);json=typedarray2json(arr);/* returns { 'type': 'Uint32Array', 'data': [ 5, 3 ] }*/arr=newInt16Array([-5,3]);json=typedarray2json(arr);/* returns { 'type': 'Int16Array', 'data': [ -5, 3 ] }*/arr=newUint16Array([5,3]);json=typedarray2json(arr);/* returns { 'type': 'Uint16Array', 'data': [ 5, 3 ] }*/arr=newInt8Array([-5,3]);json=typedarray2json(arr);/* returns { 'type': 'Int8Array', 'data': [ -5, 3 ] }*/arr=newUint8Array([5,3]);json=typedarray2json(arr);/* returns { 'type': 'Uint8Array', 'data': [ 5, 3 ] }*/arr=newUint8ClampedArray([5,3]);json=typedarray2json(arr);/* returns { 'type': 'Uint8ClampedArray', 'data': [ 5, 3 ] }*/})();</script></body></html>
@stdlib/array-reviver:revive a JSON-serialized typed array.
This package is part ofstdlib, 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 developstdlib, see the main projectrepository.
SeeLICENSE.
Copyright © 2016-2025. The StdlibAuthors.
About
Return a JSON representation of a typed array.
Topics
Resources
License
Code of conduct
Contributing
Security policy
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.
Packages0
Uh oh!
There was an error while loading.Please reload this page.