Nykakin / chompjs

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

Handle "undefined" keyword #7

Closed Nykakin closed 4 years ago

Nykakin commented 4 years ago

Error raised if undefined keyword is present in JavaScript object:

>>> chompjs.parse_js_object('{"a": undefined}')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/mariusz/Documents/Praca/venv/local/lib/python2.7/site-packages/chompjs/chompjs.py", line 27, in parse_js_object
    raise ValueError('Parser error: ... {}'.format(repr(str(exception))[1:-1]))
ValueError: Parser error: ... undefined}

Resolved by quoting unrecognised values instead automatically reporting an error:

>>> import chompjs
>>> chompjs.parse_js_object('{"a": undefined}')
{'a': 'undefined'}