Mini-Proposal: Allow psycopg Jsonb types?

Thought I’d run this past folks…

While looking at the ORM code for this question on the old ML I realised that if people wanted to use psycopg Jsonb types directly, it appears as though Django just needs to return the value during DatabaseOperations.adapt_json_value():

Study.objects.filter(data__program_name__in=[Jsonb("Program1"), Jsonb("Program2")])
--- a/django/db/backends/postgresql/
+++ b/django/db/backends/postgresql/
@@ -353,6 +353,8 @@ class DatabaseOperations(BaseDatabaseOperations):
         return None

     def adapt_json_value(self, value, encoder):
+        if type(value) == Jsonb:
+            return value
         return Jsonb(value, dumps=get_json_dumps(encoder))

     def subtract_temporals(self, internal_type, lhs, rhs):

Is there anything that Jsonb supports that’s impossible or difficult to do with Django’s current implementation? If so, I’m +1 on this. If not I’m +0.

It’s roughly equivalent to Value(…, output_field=JSONField()) :man_shrugging:

Edit: to answer the question, I’m not sure as I don’t use it myself :slight_smile:

I’m not sure I understand what you’re looking to accomplish here. The standard PostgreSQL database backend uses jsonb for the JSONField type.

What does this proposed change do differently? Can you elaborate on this?