Skip to content

Serialisation with an empty string as key fails #37

Closed

Description

@fornwall

The call json5.dumps({'': 'value'}) fails as shown:

>>> json5.dumps({'': 'value'})
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/fornwall/src/pyjson5/json5/lib.py", line 232, in dumps
    _, v = _dumps(obj, skipkeys, ensure_ascii, check_circular,
  File "/Users/fornwall/src/pyjson5/json5/lib.py", line 304, in _dumps
    s = _dump_dict(obj, skipkeys, ensure_ascii,
  File "/Users/fornwall/src/pyjson5/json5/lib.py", line 342, in _dump_dict
    valid_key, key_str = _dumps(key, skipkeys, ensure_ascii, check_circular,
  File "/Users/fornwall/src/pyjson5/json5/lib.py", line 253, in _dumps
    if (is_key and _is_ident(obj) and not quote_keys
  File "/Users/fornwall/src/pyjson5/json5/lib.py", line 442, in _is_ident
    if not _is_id_start(k[0]) and k[0] not in (u'$', u'_'):
IndexError: string index out of range

It should behave as the json module:

>>> json.dumps({'': 'value'})
'{"": "value"}'

Activity

  1. dpranke commented on Mar 26, 2020

    @dpranke
    Owner

    I've also pushed v0.9.4 to pypi to include this fix. Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions