JSON encoder still using pickle/binary encoding
Closed this issue · 4 comments
I'm using SqliteDict to have persistent storage of a dict. For debugging purposes, I want to save the dict as JSON/ASCII, so I can edit it manually.
from sqlitedict import SqliteDict
mydict = SqliteDict('./my_db.sqlite', encode=json.dumps, decode=json.loads, autocommit=True)
mydict['key'] = 'value'
However, the resulting file is a binary (I assume pickle) file. Am I doing something wrong?
The resulting file is a SQLite database: https://www.sqlite.org/fileformat.html
You can export all DB rows into plain JSON/ASCII:
with open("db_export.json", "w") as fout:
json.dump(my_sqlite_dict.items(), fout)
… but then why do you need the SQLite database at all?
Ah, I understand, then I misunderstand the library. I just want a dictionary that automatically syncs to a file on each change.
Do you have any suggestions how I can achieve that?
Yeah that's what sqlitedict
does. The file it syncs to is a SQLite database file (binary).
Thanks! Misunderstood it :) but now I found https://pypi.org/project/jsondict/ which does exactly what I want