Can't load a dictionary
Closed this issue · 2 comments
It's possible to dump a dict to a symbolic expression:
In [2]: dumps({'a': 1})
Out[2]: '(:a 1)'
Unfortunately, getting a dictionary back is not possible:
In [5]: {'a': 1} == loads(dumps({'a': 1}))
Out[5]: False
The issue here seems to be that the parser doesn't understand that symbols starting with colon are supposed to be keys:
In [6]: loads(dumps({'a': 1}))
Out[6]: [Symbol(':a'), 1]
I tested in Python 3 but Python 2 has the same problem:
In [3]: loads(dumps({'a': 1}))
Out[3]: [Symbol(u':a'), 1]
I don't think sexp is supposed to store hash tables in this format. See https://stackoverflow.com/questions/10706024/common-lisp-shorthand-to-initialize-a-hash-table-with-many-entries
It isn't clear to me that (:a 1)
is always supposed to mean a dict. I'd rather see this be optional rather than standard, if someone wants to provide a pull request for that. I'm closing this for now though. It can be re-opened or refiled if someone wants that option.