skip to Main Content

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 ?

2

Answers


  1. enumerable false makes your property transparent to some functionalities. Try setting it to true.

    Login or Signup to reply.
  2. It is explicitly documented that when using JSON.stringify:

    Only enumerable own properties are visited.

    You’ve set the property to enumerable: false so it won’t be included.

    You can’t change that behaviour of JSON.stringify. You could change your property definition.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search