C#C
C#3y ago
21 replies
Knuceles

✅ Ways to deserialize Json with dynamic model

I'm currently testing out a new API that I discovered, and I want to explore bunch of API functions and the response data. It would simply take too much time for me to define a Type class as the JSON responses are nested with dozens of arrays and objects, so is there a way for me to dynamically convert response data (HttpResponseMessage) into a C# object?

Simply using <dynamic> wouldn't convert it into a C# object
JsonSerializer.Deserialize<type>(String);


And I only want to use the optimized native JSON libraries provided in .net 6 and 7, so I wouldn't want to rely on Newton, etc. I'm also aware that there's JSON object to C# class convertor, such as https://json2csharp.com/, but I solely want to find a way to dynamically convert without needing C# classes.
Was this page helpful?