question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Object parse using json-bigint doesn't have Object function

See original GitHub issue

`var JSONbigString = require(‘json-bigint’);

var key = ‘{ “key”: 1234567890123456789 }’; var withString = JSONbigString.parse(key);

console.log(Function.prototype.toString.call(withString.constructor));`

Result `console.log(Function.prototype.toString.call(withString.constructor)); ^

TypeError: Function.prototype.toString requires that ‘this’ be a Function at toString (<anonymous>) at Object.<anonymous> (Ravi/office/mix/check.js:6:41) at Module._compile (internal/modules/cjs/loader.js:776:30) at Object.Module._extensions…js (internal/modules/cjs/loader.js:787:10) at Module.load (internal/modules/cjs/loader.js:653:32) at tryModuleLoad (internal/modules/cjs/loader.js:593:12) at Function.Module._load (internal/modules/cjs/loader.js:585:3) at Function.Module.runMain (internal/modules/cjs/loader.js:829:12) at startup (internal/bootstrap/node.js:283:19) at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)`

Expected

function Object() { [native code] }

When you use normal JSON.parse you will get the constructor as expected.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

18reactions
gitpaladincommented, Sep 15, 2020

use the last version instead

npm install --save json-bigint@0.4.0

After update to 1.0.0, lots of weird problem occurred. I’ve never mind some library do some prototype pollution. But there is no options to keep the compatibility to the older version.

2reactions
klesuncommented, Feb 3, 2021

I filed a PR to add an option to preserve prototype properties on the parsed objects: https://github.com/sidorares/json-bigint/pull/47

var JSONbig = require('json-bigint');
var JSONBigInt = JSONbig({ objectBaseClass: Object }); // default is null
var key = '{ "key": 1234567890123456789 }';
// should not result in TypeError thanks to `objectBaseClass: Object`
console.log(Function.prototype.toString.call(withString.constructor));`

Upd.: oh, I thought built-in BigInt support was not available in v0.4.0, but apparently it is, so, yeah, better to just stick to v0.4.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

missing hasOwnProperty function after Parse #38 - GitHub
it seems Object parsed by JSONbig lost hasOwnProperty function: ... Objects can be created with null prototype, in that case they won't have...
Read more >
node.js - Is there any proper way to parse JSON with large ...
Not with built-in JSON.parse. You'll need to parse it manually and treat values as string (if you want to do arithmetics with them...
Read more >
bigint - # - json - DEV Community ‍ ‍
As of this writing, JavaScript's JSON. parse cannot serialize the new JavaScript type BigInt . If you try to just JSON. stringify(data) you...
Read more >
json-bigint - npm
JSON.parse/stringify with bigints support. Based on Douglas Crockford JSON.js package and bignumber.js library. Native Bigint was added to JS ...
Read more >
JSON.stringify() - JavaScript - MDN Web Docs
If replacer is anything other than a function or an array (e.g. null or not provided), all string-keyed properties of the object are...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found