Looking for flexible deserialization option - it should ignore data type gracefully and have a provision to provide fields(full path) which needs to ignored from deserialization process.
Loading
Looking for flexible deserialization option - it should ignore data type gracefully and have a provision to provide fields(full path) which needs to ignored from deserialization process.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Abhishek ChadhaRank #402 · 6.2K reputationPosted Jun 5, 2024, 8:11 AM EDT
you can try with newtonsoft.json
Jayraj ChhayaRank #304 · 8.2K reputationPosted Jun 5, 2024, 9:35 AM EDT
In C#, you can achieve flexible JSON deserialization using libraries like Newtonsoft.Json (Json.NET). This library provides various options for deserialization, including handling data type mismatches gracefully and ignoring specific fields during the process.
To ignore specific fields during deserialization, you can use the
[JsonIgnore]attribute from Json.NET.using Newtonsoft.Json; public class MyDataModel { public string Name { get; set; } [JsonIgnore] public int Age { get; set; } } // Deserialize JSON with ignored fields MyDataModel data = JsonConvert.DeserializeObject(jsonString);Vishal YelveRank #178 · 13.6K reputationPosted Jun 5, 2024, 11:27 AM EDT
Hi Rajendra,
try to use
[JsonIgnore]tag above ur model propertyexample
public class Employee { public string Email { get; set; } public bool Active { get; set; } [JsonIgnore] public DateTime CreatedDate { get; set; } }and then use this
var result = JsonConvert.DeserializeObject(jsonString);Jaydeep PatilRank #205 · 11.7K reputationPosted Jun 5, 2024, 1:42 PM EDT
Newtonsoft.Json
Jaimin ShethiyaRank #177 · 13.7K reputationPosted Jun 7, 2024, 1:26 AM EDT
Hello Rajendra,
You can refer below links.
https://www.newtonsoft.com/json
https://www.nuget.org/packages/Newtonsoft.Json/
if you can provide some use cases then, it will helpful to us to better guide.
Thanks