Is it possible to exclude certain fields from json string?
Here are some pseudo codes
var x = { x:0, y:0, divID:"xyz", privateProperty1: 'foo', privateProperty2: 'bar' }
I want privateProperty1 and privateproperty2 to appear in json string
So, I thought, I can use the replicate function for stringify
function replacer(key,value) { if (key=="privateProperty1") then retun "none"; else if (key=="privateProperty2") then retun "none"; else return value; }
and in stringify
var jsonString = json.stringify(x,replacer);
But in jsonString, I still see it as
{...privateProperty1:value..., privateProperty2:value }
I need a string without privateproperties in them.
json javascript
Nilesh Feb 06 2018-11-11T00: 00Z
source share