From aac36896494aa554ce64897b68ddb852773189f6 Mon Sep 17 00:00:00 2001 From: Artur Klesun Date: Wed, 3 Feb 2021 10:17:57 +0200 Subject: [PATCH] Add `objectBaseClass` option which can be set to `Object` instead of `null` to preserve prototype methods like `hasOwnProperty` https://github.com/sidorares/json-bigint/issues/38 --- lib/parse.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/parse.js b/lib/parse.js index bb4e5eb..347890d 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -88,6 +88,7 @@ var json_parse = function (options) { useNativeBigInt: false, // toggles whether to use native BigInt instead of bignumber.js protoAction: 'error', constructorAction: 'error', + objectBaseClass: null, // pass `Object` if you require prototype methods like `hasOwnProperty` for the compatibility with JSON.parse() }; // If there are options, then use them to override the default _options @@ -327,7 +328,7 @@ var json_parse = function (options) { // Parse an object value. var key, - object = Object.create(null); + object = Object.create(_options.objectBaseClass); if (ch === '{') { next('{');