0

I know that both single and double quotes will work same way in python, but why it is behaving differently in following two cases

>>> import json
>>> json.loads('{"M":2}')
{u'M': 2}

And in

>>> json.loads("{'M':2}")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "c:\p\python\lib\json\__init__.py", line 326, in loads
    return _default_decoder.decode(s)
  File "c:\p\python\lib\json\decoder.py", line 360, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "c:\p\python\lib\json\decoder.py", line 376, in raw_decode
    obj, end = self.scan_once(s, idx)
ValueError: Expecting property name: line 1 column 1 (char 1)

Thanks in advance

Rajesh Kumar
  • 1,270
  • 4
  • 15
  • 31

1 Answers1

1
>>> json.loads('{"M":2}')
{u'M': 2}

that returns a python dictionary

JSON only accepts double quotes.

json.loads("{'M':2}")

This is not a valid JSON.

See: jQuery.parseJSON single quote vs double quote

Community
  • 1
  • 1
Paco
  • 4,520
  • 3
  • 29
  • 53