1

One of the features in NewtonSoft's Json.Net parser is the support of unquoted property name, for example {test:"abc"}. Is it possible to turn off this feature so the json parser will throw an error when it parses a json string with unquoted property name?

dtai
  • 11
  • 1
  • It doesn't look that way. The method that parses an unquoted property name is [`JsonTextReader.ParseUnquotedProperty()`](https://github.com/JamesNK/Newtonsoft.Json/blob/master/Src/Newtonsoft.Json/JsonTextReader.cs#L1591) called from [`JsonTextReader.ParseProperty()`](https://github.com/JamesNK/Newtonsoft.Json/blob/master/Src/Newtonsoft.Json/JsonTextReader.cs#L1530). The linked source doesn't seem to have an option implemented to force an exception to be thrown for an unquoted property. – dbc Aug 17 '17 at 06:32
  • Thanks. I saw that piece of code too. I am just wondering if there is another type of reader... probably not. – dtai Aug 17 '17 at 14:20
  • Turn if off? I am gettin webhooks with unquoted properties and NET6 is saying character at position x is invalid. That is just a character of the property.. I cant change what junk people send me so how do RELAX this?? sigh, facepalm – Piotr Kula Apr 04 '23 at 21:20

1 Answers1

0

What you can do is to deserialize and then serialize again and compare with original input. That will detect missing quotes. Even if this is not performance efficient, it is very simple and serves well when the relevant code performance does not matter much.

Guy L.
  • 153
  • 1
  • 9