Nykakin / chompjs

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

Improve handling of newlines #15

Closed Nykakin closed 4 years ago

Nykakin commented 4 years ago

Exception present if Windows newlines are present before closing , that needs to be removed:

>>> chompjs.parse_js_object("{'foo': 0, \r\n}")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "chompjs/chompjs.py", line 34, in parse_js_object
    return json.loads(parsed_data)
  File "/usr/lib/python2.7/json/__init__.py", line 339, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python2.7/json/decoder.py", line 364, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python2.7/json/decoder.py", line 380, in raw_decode
    obj, end = self.scan_once(s, idx)
ValueError: Expecting property name: line 1 column 10 (char 9)