This project has moved. For the latest updates, please go here.

Ignoring empty lists/arrays

Feb 6, 2012 at 9:04 PM

Reducing serialized Json size by ignoring null objects is already a cool feature!


Would there be something similar to ignore empty lists?

E.g. if I had a Customer object, with Name and FirstName set, but ActiveOrders being empty (not null - wich is what I get from EF) it would save another notable amount of bytes if we got this:


{ "Name":"Doe", "NameFirst":"Joe"}

and not this:

{ "Name":"Doe", "NameFirst":"Joe", "ActiveOrders":[]}



Mar 24, 2012 at 7:28 PM

I could really use this feature. Is there a way to accomplish this? I can't seem to make it work.

Mar 26, 2012 at 2:56 PM
Edited Mar 26, 2012 at 2:59 PM

I think the problem is that omitting the property implies that it should be null when it gets deserialized (this is, afaik, how most serializers work, JSON or otherwise, if they don't throw an exception). An empty list and a null list don't necessarily mean the same thing, and there'd be no way to tell the difference between the two on the deserializing end.

Mar 27, 2013 at 11:53 PM
right now it deserialize empty arrays and list as null, is this on purpose?
because in my app i want that if the user send an empty array it's mean to clear the list.
if it send a null value or doesn't send it so it's mean not to update that property