Deserialize data into a dynamic
type when using System.Text.Json
.
- .NET Standard 2.0 compatible
- Available from nuget.org
class MyClass {
... etc ...
[JsonInclude]
[System.Text.Json.Serialization.JsonConverter(typeof(SystemTextJson.DynamicConverter.Converter))]
public dynamic MyDynamicData { get; set; }
... etc ...
}
var result = JsonSerializer.Deserialize<MyClass>(json);
var val = result.MyDynamicData.some._dynamic.property.somewhere;
Alternatively ...
services.AddControllers().AddJsonOptions(options =>
options.JsonSerializerOptions.Converters.Add(new SystemTextJson.DynamicConverter.Converter())
);