© 2026 Hedgehog Software, LLC
record Item(string Text, int? Number); List<Item> items = new(); JsonSerializerOptions options = new() { DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingDefault, }; string json = JsonSerializer.Serialize(items, options);
null
[ { "Text": "Test" }, { "Text": "test 2", "Number": 1 }, { "Text": "test 3", "Number": null, // Tell the serializer to only serialize this null value } ]
Join the Discord to ask follow-up questions and connect with the community
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
62,470 Members