Ignoring null fields in Json.net

Yes you need to use JsonSerializerSettings.NullValueHandling = NullValueHandling.Ignore.

But because structs are value types you need to mark Field2, Field3 nullable to get the expected result:

public struct structA
{
    public string Field1;
    public structB? Field2;
    public structB? Field3;
}

Or just use classes instead of structs.

Documentation: NullValueHandling Enumeration

Leave a Comment