Is there a way to conditionally exclude elements from JSON serialization? I am using C # in a .NET4 application with WebAPI. I have [DataMember]it [ScriptIgnore]already in my classes, and everything works fine. What I want to do does not include specific properties at runtime based on the value of the property
For example, I can only serialize List<Foo> myFoowhen
myFoo != null && myFoo.Count > 0
JSON is translated back to my own JS objects on the client, which will have all the properties created already as myFoo: []. There is simply no need to send them in JSON to the client, since it will essentially not affect the object and will only send more data and use more processing on the client. This is a very JS heavy HTML5 mobile site and I try to reduce as much data and processing as possible.
source
share