json-parse-bigint
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

json-parse-bigint

convert all the big integers (≥ 16 digits) to string in JSON before JSON.parse

Features

Simple, No dependencies, Less than 1KB

Install

Browser:

<script src='path/to/safe-json.js'></script>

Node.js:

npm install json-parse-bigint
const JsonParseBigInt = require('json-parse-bigint');

ES6 module:

import JsonParseBigInt from 'json-parse-bigint'

Example

var json = '{ "id": 298295614833079897, "name": "test", "is_liked": 1 }';
console.log(JSON.parse(json)); // {id: 298295614833079900, name: "test", is_liked: 1}
console.log(JsonParseBigInt(json)); // {id: "298295614833079897", name: "test", is_liked: 1}
// Use Globally
JSON.parse = JsonParseBigInt
console.log(JSON.parse(json)); // {id: "298295614833079897", name: "test", is_liked: 1}

// Someone try to confuse
var json = '{ "id": 298295614833079897, "name": "\\"test\\": 298295614833079897, ", "is_liked": 1 }';
// No Problem :)
console.log(JsonParseBigInt(json)); // {id: "298295614833079897", name: ""test": 298295614833079897, ", is_liked: 1}

Licence

The MIT Licence.

Package Sidebar

Install

npm i json-parse-bigint

Weekly Downloads

590

Version

1.0.4

License

MIT

Unpacked Size

2.19 kB

Total Files

4

Last publish

Collaborators

  • quickjack