missing hasOwnProperty function after Parse
See original GitHub issueI got big number serializing problem in JSON, so I decide to override JSON.parse
and JSON.stringify
with this package globally, then I encountered some errors in other js codes,
it seems Object
parsed by JSONbig
lost hasOwnProperty
function:
import * as JSONbig from "json-bigint";
var json = '{ "value" : 9223372036854775807, "v2": 123 }';
console.log(
JSON.parse(json).hasOwnProperty("value")
);
console.log(
JSONbig.parse(json).hasOwnProperty("value")
);
module def for typescript:
declare module "json-bigint" {
function parse(text: string, reviver?: (this: any, key: string, value: any) => any): any;
function stringify(value: any, replacer?: (this: any, key: string, value: any) => any, space?: string | number): string;
function stringify(value: any, replacer?: (number | string)[] | null, space?: string | number): string;
}
got output:
true
console.log(JSONbig.parse(json).hasOwnProperty("value"));
^
TypeError: JSONbig.parse(...).hasOwnProperty is not a function
at Object.<anonymous> (\resources\json-bigint\dist\index.js:27:33)
at Module._compile (internal/modules/cjs/loader.js:1138:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
at Module.load (internal/modules/cjs/loader.js:986:32)
at Function.Module._load (internal/modules/cjs/loader.js:879:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
at internal/main/run_main_module.js:17:47
error Command failed with exit code 1.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:9 (3 by maintainers)
Top Results From Across the Web
hasOwnProperty is not a function in Node.js? - Stack Overflow
A way around the error is to call hasOwnProperty on Object explicitly, and bind it to the object, like so: // Calls "hasOwnProperty"...
Read more >Object.prototype.hasOwnProperty() - JavaScript | MDN
The hasOwnProperty() method returns a boolean indicating whether the object has the specified property as its own property (as opposed to ...
Read more >CoffeeScript
In JavaScript, the this keyword is dynamically scoped to mean the object that the current function is attached to. If you pass a...
Read more >Lodash Documentation
identity] (Function): The iteratee invoked per element. Returns. (Array): Returns the new array of filtered values. Example. _.differenceBy ...
Read more >ECMAScript® 2023 Language Specification - TC39
... 4.4.32 Symbol type; 4.4.33 Symbol object; 4.4.34 function; 4.4.35 built-in function; 4.4.36 property; 4.4.37 method; 4.4.38 built-in method ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@goxr3plus this is a recent change, to add better protection from prototype pollution I changed the way objects are created from
{}
toObject.create(null)
, unfortunately this has a side effect you posted. Not sure if there is a better way to make it to turn'{"__proto___": { "test": true }}'
string into{__proto___: {test: true }}
object rather than{}
with{test: true}
prototypeObjects can be created with null prototype, in that case they won’t have
.hasOwnProperty
method.Safer way to call: