C
C#3y ago
Sernik

Deserialize JSON to dynamic object without Newtonsoft.Json

Hi, is there a way to deserialize json object to dynamic in .net? ideally from HttpContent. I don't want to use additional dependency, but i can't find vanilla solution. Thanks for help!
24 Replies
Thinker
Thinker3y ago
Why do you want a dynamic object? Also System.Text.Json exists and is completely built-in.
Sernik
SernikOP3y ago
i don't want to create a lot of classes for processing api response ill check it, thanks
hoggy077
hoggy0773y ago
you dont need to, you can deserialize to an object (and probably to a dynamic) and use .GetProperty
Thinker
Thinker3y ago
Well you really should
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Thinker
Thinker3y ago
You can use special paste or any online JSON to C# converter Don't use dynamic. Period.
Sernik
SernikOP3y ago
this solution sounds cool ill try that
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
hoggy077
hoggy0773y ago
I dont recommend it. Like, I seriously dont recommend it
Sernik
SernikOP3y ago
hmm okay ill create that classes Thanks for help guys! wow, this is very cool, thanks
Angius
Angius3y ago
$jsongen
MODiX
MODiX3y ago
Use https://app.quicktype.io or https://json2csharp.com to generate classes from your JSON
Instantly parse JSON in any language | quicktype
Whether you're using C#, Swift, TypeScript, Go, C++ or other languages, quicktype generates models and helper code for quickly and safely reading JSON in your apps. Customize online with advanced options, or download a command-line tool.
Convert JSON to C# Classes Online - Json2CSharp Toolkit
Convert any JSON object to C# classes online. Json2CSharp is a free toolkit that will help you generate C# classes on the fly.
Cisien
Cisien3y ago
are those sites defaulting to system.text.json yet?
Cisien
Cisien3y ago
nope
Cisien
Cisien3y ago
they are good enough for creating the classes, but any helper methods/suggestions in comments will lead you down the path of newtonsoft.json. There's also a few difference to keep in mind, for example, system.text.json is much more strict -- it won't ignore case differences between the json and the c# class by default, for example.
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Cisien
Cisien3y ago
asp.net core does
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Cisien
Cisien3y ago
i'm pretty sure it supports it with s.t.j
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Cisien
Cisien3y ago
so yeah, it is based on newtonsoft still reading more of that page, yeah, it's still newtonsoft, even if you're using s.t.json normally, this doc tells you how to get it working with newtonsoft
KKSK@🌸🎵🌸🎵🌸
LitJson Although I think Newtonsoft still rocks I had the same issue few months ago Haha
Want results from more Discord servers?
Add your server