New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@j-o-r/jsonext

Package Overview
Dependencies
Maintainers
0
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@j-o-r/jsonext

Extended JSON, keep typed arrays in their orginal form, backwards compatible with original JSON

  • 1.0.0
  • latest
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

JSONEXT

JSONEXT is an extension to JSON that preserves the data type of typed arrays and BigInts.

Installation

npm i @j-o-r/jsonext --save

Usage

Stringify

To stringify an object with typed arrays:

import JSONEXT from '@j-o-r/jsonext'
const typedArray = new Float32Array([1.1, 2.2, 3.3]);
const jsonString = JSONEXT.stringify({ array: typedArray });
console.log(jsonString); // Output: {"array":{"_dT_":"f32a","_dA_":[1.1,2.2,3.3]}}

Parse

To parse a JSON string back into its original form:

const parsedObject = JSONEXT.parse(jsonString);
console.log(parsedObject.array instanceof Float32Array); // true

Features

  • Typed Arrays: Preserves the type of arrays like Float32Array, Int8Array, etc.
  • BigInt: Converts BigInt to string representation for JSON compatibility.
  • Compatibility: Works with standard JSON methods but extends functionality.

Limitations and Notes:

  • Ensure that the _dT_ and _dA_ keys do not conflict with your data keys.
  • Performance might be impacted for large objects due to type checking.
  • Default handling for handling known types in parsing.

License

This project is licensed under the APACHE 2.0 License. See the LICENSE file for details.

Keywords

FAQs

Package last updated on 15 Jan 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc