JSON.stringify(data) is removing certain of data
Tried the below resolution but it did not work either
const obj = {
prop1: 'value1'
};
Object.defineProperty(obj, 'prop2', {
value: 'value2',
enumerable: false
});
console.log(JSON.stringify(obj));
Is there a way to stop JSON.stringify from removing extracts of data ?
JSON.stringifyto find it?JSON.stringifyis not meant to produce a perfect replica of all possible JavaScript objects. In fact it's intentionally restricted to a subset of JavaScript to be easily transferrable.JSON.stringifyonly includes own, enumerable properties with string keys, not other kinds of properties (inherited, non-enumerable, properties with Symbol keys). In your example, the property being omitted is non-enumerable, so it's not included.JSON.stringify({x:undefined})will do something you might not expect.