Search code examples
pythonjsonsimplejson

Python simplejson not converting true


Why doesn't this work? I'm reading for simplejson JsonDecoder, true should be parsable and translated to True.

% python
>>> import simplejson as json
>>> print json.loads({"bool":true})
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'true' is not defined
>>>

Solution

  • The input to loads should be a string:

    >>> json.loads('{"bool":true}')
    {u'bool': True}