hey I have a array object something like this
[{
public: "public",
private: "private",
[{
properties: {...
},
instance: {.....
}
}, {...
}, {...
}]
}, {...
}, {....
}]
Here the outer most array contains object of class A, which has a some public props, some private porps and it also contains an array which contains object of class B, which also contains some public and private fields.
so basically this is my hierarchy
array = [A1,A2,A3,A4,....]//object of A
var A = function(){
var Const = function(){
this.public_prop;
this.private_prop;
this.list = [B1,B2,B3,B4]// objects of B
}
//.........
return Const;
}();
var B = function(){
var Const = function(){
this.public_prop;
this.private_prop;
}
//.........
return Const;
}();
Now while stringifying(serialzing) it I want to only include public prop and the arrays in the serialized string.
for example for the above JSON representation i want something like this
[{
public: "public",
[{
properties: {...
}
}, {...
}, {...
}]
}, {...
}, {....
}]
now i can create a function getState() in each class which will only return fields which needs to be stringified, but i cannot seem to find a way to make the native implementation of JSON.stringify call the method before serializing it. Is there some way of accomplishing this?
I refered Hide certain values in output from JSON.stringify(), but it only explains how to exclude simple numeric or string prop in single hierarchy, but how to exclude props in multiple hierarchy?
Note:All my classes follow module-pattern
var result = JSON.stringify(myjson, function(key, val) {
if (key !== "private")
return val;
});
Your object example at the top isn't valid syntax, but to exclude properties named "private"
, this should work.