Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stringify a whole Javascript Object including __proto__ properties?

I am sorry if this is a duplicate, so far I couldn't find the same question.

I have an Object with various methods in my __proto__ member. Let's call the type of this object myObjectType.

Later on I have to do a JSON.stringify(myObjectType). The problem is that then when I build my object from the previous obtained JSON string the type of my Object is plain Object, I lost all the methods I had.

Does any one see why ?

like image 442
Spredzy Avatar asked Apr 26 '11 12:04

Spredzy


People also ask

How do you Stringify an object in JavaScript?

Stringify a JavaScript ObjectUse the JavaScript function JSON.stringify() to convert it into a string. const myJSON = JSON.stringify(obj); The result will be a string following the JSON notation.

What does __ proto __ mean in JavaScript?

__proto__ is a way to inherit properties from an object in JavaScript. __proto__ a property of Object. prototype is an accessor property that exposes the [[Prototype]] of the object through which it is accessed. POSTly is a web-based API tool that allows for fast testing of your APIs (REST, GraphQL).

Does JSON Stringify work on objects?

JSON. stringify() will encode values that JSON supports. Objects with values that can be objects, arrays, strings, numbers and booleans. Anything else will be ignored or throw errors.

What is difference between __ proto __ and prototype?

The prototype property is set to function when it is declared. All the functions have a prototype property. proto property that is set to an object when it is created using a new keyword. All objects behavior newly created have proto properties.


1 Answers

search google for javascript object serialization.

GSerializer library

like image 163
z33m Avatar answered Oct 05 '22 11:10

z33m