Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

deserializing json without quoted property names with JsonSerializer.Deserialize (.net core)

I know that the specs for JSON says that propertynames (keys) should be surrounded by quotes.

But I have a lot of files that I need to read that contains data where the keys might not be quoted.

Earlier, before migration to Core, I used JavaScriptSerializer (that accepts keys without quotes ) but that doesn't exist in .net core.

Any ideas, or alternatives? I am still searching. But after 4 hours I thought that maybe you guys know this.

So, how can I read "{ apa: 23 }" and create a dictionary in .net core?

/thanks

like image 200
eric Avatar asked Dec 12 '25 02:12

eric


1 Answers

Install-Package Newtonsoft.Json



string json = @"{
      'Name': 'name',
      'Description': 'des'
    }";
Test test = JsonConvert.DeserializeObject<Test>(json);
like image 193
Ravi Maurya Avatar answered Dec 16 '25 08:12

Ravi Maurya



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!