1

Is there a way that I can instruct WCF to accept JSON that is formatted using either single quotes (as opposed to double quotes):

{
   'foo': 'bar'
}

Or using non-quoted identifiers like so:

{
    foo: 'bar'
}

As it is, it seems like JSON will only be accepted if it is formatted like so:

{
    "foo": "bar"
}

Using either of the first two example results in a 400 (bad request).

Daniel Schaffer
  • 56,753
  • 31
  • 116
  • 165

2 Answers2

2

The first two examples are invalid JSON texts. http://www.ietf.org/rfc/rfc4627.txt

object = begin-object [ member *( value-separator member ) ]
end-object

member = string name-separator value

string = quotation-mark *char quotation-mark

quotation-mark = %x22      ; "
James
  • 9,064
  • 3
  • 31
  • 49
  • That the first example is illegal does not help much when many JavaScript frameworks are using single quote around property name as fx https://github.com/request/request – Lars Ladegaard May 10 '18 at 20:39
  • @LarsLadegaard who cares about javascript? – James May 10 '18 at 21:03
2

DataContractJsonSerializer always writes strict JSON.

At various points during deserialization (generally missing end tags for arrays or objects, or improper escaping, or improperly formatted numbers), it will accept incorrect, non-strict JSON.

However, I can tell you definitively that this is not one of those cases. DataContractJsonSerializer always requires double-quoted strings for JSON.

Hope this helps!

Oleks
  • 31,955
  • 11
  • 77
  • 132
krisragh MSFT
  • 1,908
  • 1
  • 13
  • 22