Ignore property when null using the new Net Core 3.0 Json
I’m looking at .Net Core 3.1, where this should ignore null values services.AddControllers().AddJsonOptions(options => { options.JsonSerializerOptions.IgnoreNullValues = true; }); While in .NET 5 and later, set JsonSerializerOptions.DefaultIgnoreCondition to JsonIgnoreCondition.WhenWritingNull: services.AddControllers().AddJsonOptions(options => { options.JsonSerializerOptions.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull; }); Note, the above isn’t per property/attribute, although there is an attribute which may be helpful JsonIgnoreAttribute. An alternative, to … Read more