diff --git a/json5/lib.py b/json5/lib.py index d588005..5b2b0ae 100644 --- a/json5/lib.py +++ b/json5/lib.py @@ -439,7 +439,7 @@ def _dump_str(obj, ensure_ascii): def _is_ident(k): k = str(k) - if not _is_id_start(k[0]) and k[0] not in (u'$', u'_'): + if not k or not _is_id_start(k[0]) and k[0] not in (u'$', u'_'): return False for ch in k[1:]: if not _is_id_continue(ch) and ch not in (u'$', u'_'): diff --git a/tests/lib_test.py b/tests/lib_test.py index 511f172..9651545 100644 --- a/tests/lib_test.py +++ b/tests/lib_test.py @@ -422,6 +422,9 @@ def test_supplemental_unicode(self): # we can't test this there. pass + def test_empty_key(self): + self.assertEqual(json5.dumps({'': 'value'}), '{"": "value"}') + if __name__ == '__main__': # pragma: no cover unittest.main()