Search code examples
pythonjsonsimplejson

Is there any way to make simplejson less strict?


I'm interested in having simplejson.loads() successfully parse the following:

{foo:3}

It throws a JSONDecodeError saying "expecting property name" but in reality it's saying "I require double quotes around my property names". This is annoying for my use case, and I'd prefer a less strict behavior. I've read the docs, but beyond making my own decoder class, I don't see anything obvious that changes this behavior.


Solution

  • You can use YAML (>=1.2)as it is a superset of JSON, you can do:

    >>> import yaml
    >>> s = '{foo: 8}'
    >>> yaml.load(s)
    {'foo': 8}