Nykakin / chompjs

Parsing JavaScript objects into Python data structures
MIT License
197 stars 11 forks source link

Parsing unquoted properties starting with reserved JS keywords fails #34

Closed Nykakin closed 2 years ago

Nykakin commented 2 years ago

The lib can handle unquoted properties:

>>> chompjs.parse_js_object('{aaaa: 10}')
{'aaaa': 10}

But if such a property name starts with reserved JS keywords (like true or null) it fails:

>>> chompjs.parse_js_object('{trueaaaa: 10}')
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/home/mariusz/Documents/Praca/venv/lib/python3.9/site-packages/chompjs/chompjs.py", line 25, in parse_js_object
    return json.loads(parsed_data, **json_params)
  File "/usr/lib/python3.9/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.9/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.9/json/decoder.py", line 353, in raw_decode
    obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)