Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

json-bigint

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-bigint

JSON.parse with bigints support

  • 0.2.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
7.9M
decreased by-16.47%
Maintainers
1
Weekly downloads
 
Created

What is json-bigint?

The json-bigint npm package is designed to handle JSON data that includes very large numbers, which can exceed JavaScript's Number.MAX_SAFE_INTEGER. It provides functionality to parse and stringify JSON while preserving the precision of large integers.

What are json-bigint's main functionalities?

Parsing JSON with BigInt

This feature allows you to parse JSON strings that contain very large numbers. The parsed numbers are represented as BigInt objects, preserving their precision.

const JSONbig = require('json-bigint');
const jsonString = '{"bigNumber": 9223372036854775807}';
const parsed = JSONbig.parse(jsonString);
console.log(parsed.bigNumber.toString()); // '9223372036854775807'

Stringifying JSON with BigInt

This feature allows you to stringify JavaScript objects that contain BigInt values. The BigInt values are converted to strings in the resulting JSON string to maintain their precision.

const JSONbig = require('json-bigint');
const obj = { bigNumber: BigInt('9223372036854775807') };
const jsonString = JSONbig.stringify(obj);
console.log(jsonString); // '{"bigNumber":"9223372036854775807"}'

Customizing BigInt handling

This feature allows you to customize how BigInt values are handled. For example, you can configure json-bigint to store large numbers as strings instead of BigInt objects.

const JSONbig = require('json-bigint')({ storeAsString: true });
const jsonString = '{"bigNumber": 9223372036854775807}';
const parsed = JSONbig.parse(jsonString);
console.log(parsed.bigNumber); // '9223372036854775807' (as a string)

Other packages similar to json-bigint

Keywords

FAQs

Package last updated on 07 Jan 2017

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