Hi,

I have a problem with a custom JSON type, which is not preserving keys 
order, despite that I'm using python 3.8.

Here is the type definition and usage:

```
import json
from sqlalchemy import Column, Integer
from sqlalchemy.types import TypeDecorator, TEXT
from sqlalchemy.ext.mutable import MutableDict

class JSONType(TypeDecorator):
    impl = TEXT

    def process_bind_param(self, value, dialect):
        if value is not None:
            value = json.dumps(value)
        return value

    def process_result_value(self, value, dialect):
        if value is not None:
            value = json.loads(value)
        return value

JSONDict = MutableDict.as_mutable(JSONType)

Base = automap_base()

class Picture(Base):
    __tablename__ = 'picture'
    id = Column(Integer, primary_key=True)
    data = Column(JSONDict)
```

When I'm storing values in the data field (values are nested elements of 
different types), store the picture in database and reload it, the keys 
order of data dict is not preserved. I'm don't understand why, because the 
version of python I'm using is supposed to keep the dict insertion order.

Have you some idea how to solve that ? The JSON keys order is important for 
my application.

Thank you

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/2023e849-37d4-43e5-bd1f-02829474c62bn%40googlegroups.com.

Reply via email to