.NET Core: Remove null fields from API JSON response
问题 On a global level in .NET Core 1.0 (all API responses), how can I configure Startup.cs so that null fields are removed/ignored in JSON responses? Using Newtonsoft.Json, you can apply the following attribute to a property, but I'd like to avoid having to add it to every single one: [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] public string FieldName { get; set; } [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] public string OtherName { get; set; } 回答1: In Startup