Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Too lenient with trailing commas in dicts #303

Closed
slai opened this issue Mar 22, 2018 · 1 comment · Fixed by #323
Closed

Too lenient with trailing commas in dicts #303

slai opened this issue Mar 22, 2018 · 1 comment · Fixed by #323

Comments

@slai
Copy link

slai commented Mar 22, 2018

It looks like the JSON conformance issue mentioned in #50 also affects dicts -

In [1]: import json, ujson

In [2]: json_str = '{"hello": "world",}'

In [3]: json.loads(json_str)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-3-e626482e668e> in <module>()
----> 1 json.loads(json_str)

/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.pyc in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
    336             parse_int is None and parse_float is None and
    337             parse_constant is None and object_pairs_hook is None and not kw):
--> 338         return _default_decoder.decode(s)
    339     if cls is None:
    340         cls = JSONDecoder

/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.pyc in decode(self, s, _w)
    364 
    365         """
--> 366         obj, end = self.raw_decode(s, idx=_w(s, 0).end())
    367         end = _w(s, end).end()
    368         if end != len(s):

/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.pyc in raw_decode(self, s, idx)
    380         """
    381         try:
--> 382             obj, end = self.scan_once(s, idx)
    383         except StopIteration:
    384             raise ValueError("No JSON object could be decoded")

ValueError: Expecting property name: line 1 column 19 (char 18)

In [4]: ujson.loads(json_str)
Out[4]: {u'hello': u'world'}
@timdawborn
Copy link
Contributor

Fixed in #323.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants