Some extensions to add more features to text.json.
If you like or are using this project to learn or start your solution, please give it a star. Thanks!
Big thanks to all of the great contributors to this project!
Install DevBetter.JsonExtensions from Nuget using:
(in Visual Studio)
Install-Package DevBetter.JsonExtensions
(using the dotnet cli)
dotnet add package DevBetter.JsonExtensions
Will help to not go to exception when the property set to {} in json.
You can enable it by calling SetMissingMemberHandling
.
var jsonString = @"{""Id"":5, ""Title"": ""Title"",""TemperatureC"": 28,""CreatedDate"": {}, ""Days"": [""Sunday""]}";
var deserializeOptions = new JsonSerializerOptions()
.SetMissingMemberHandling(MissingMemberHandling.Ignore);
var weatherForecast = JsonSerializer.Deserialize<WeatherForecast>(jsonString, deserializeOptions);
Please check the unit tests for more examples here