question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Expose serialization options in sqlite_ext.JSONField (or use better defaults)

See original GitHub issue

Currently, sqlite_ext.py seems to use json.dumps without any options, which means the defaults separators=(', ', ': ') and ensure_ascii=True are assumed. These are a waste of space, and ensure_ascii also reduces human readability of non-ASCII text without real world benefit (since SQLite is Unicode-safe).

Compare the result of SQLite JSON1 extension’s builtin json function:

INSERT INTO entry(doc) VALUES(json('{ "lang":  "中文" }'));

=>

INSERT INTO entry VALUES(1,'{"lang":"中文"}');

and peewee:

Entry.insert(doc=dict(lang='中文'))

=>

INSERT INTO entry VALUES(1,'{"lang": "\u4e2d\u6587"}');

It would be nice if serialization options are exposed, or just use separators=(',', ':') and ensure_ascii=False.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:13 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
leandrosalocommented, Nov 9, 2022

If for some reason someone ends up here for the Your version of psycopg2 does not support JSON. exception then try to run pip install --upgrade psycopg2 and try again. Hope this helps someone even tho it looks like a dumb or obvious solution.

0reactions
czitiancommented, Jan 29, 2020

WOW, thanks for the fast reply. I didn’t realize that. BinaryJSONField seems work fine, even without custom dumps function.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using Django's JSONField? You probably don't need it. Here's ...
If you're using Postgres with Django and importing the JSONField object, you're using JSONB. This is the default in recent Django versions and ......
Read more >
JSONField in serializers - Django REST Framework
This article revolves around JSONField in Serializers in Django REST ... Defaults to False. encoder – Use this JSON encoder to serialize ......
Read more >
How to set the default of a JSONField to empty list in Django ...
What is the best way to set a JSONField to have the default value of a new list in django ? Context. There...
Read more >
Gson Builder — How to Ignore Fields with @Expose
@Expose is optional and offers two configuration parameters: serialize and deserialize . By default everything is set to true .
Read more >
peewee Documentation [image] - manpages.ubuntu!
To view the available test runner options, use: python runtests.py --help NOTE: ... TextField() attributes = JSONField(default=house_defaults) The database ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found