Disable Support for Reading (Invalid JSON) Single Quote Strings

Newtonsoft.Json for C# supports reading stuff like {'key':'value'} but thats improper JSON. Is it possible to disable that so it parses and reads more like PHP (Where'as PHP doesnt support {'key':'value'} but {"key":"value"})

Jon Skeet
people
quotationmark

You could write your own JsonReader subclass to perform this, but the JsonTextReader class (which is the most commonly used one, as far as I'm aware) doesn't support this. From the ParseValue method, for example:

case '"':
case '\'':
    ParseString(currentChar, ReadType.Read);
    return true;

I have a strict JSON tokenizer in Google.Protobuf - it's internal, but should give you some idea that it's not terribly tricky to write such a tokenizer yourself. That doesn't help you if you really want to use Json.NET other than the strictness, of course.

You might want to read and potentially vote/comment on issue 646 in the Json.NET repo, where I requested a "strict mode" as well. (There's a suggested alternative approach there, too - although it feels like a bit of a hack.)

people

See more on this question at Stackoverflow