1

I need to store JSON in Azure SQL Database, e.g.:

id    something         json_document
 1     Foo West      {"p1":3, "p3":4}
 2     Foo East    {"p1":13, "p3":34}
 3    Foo North    {"p1":23, "p3":44}

Recently Microsoft announced better support for storing JSON in thier SQL databases: https://learn.microsoft.com/en-us/sql/relational-databases/json/json-data-sql-server?view=sql-server-2017 . Is there a way to use this feature with SQLAlchemy's ORM?

What I'd love to have it something along these lines:

class Mytable(db.Model):
    id = db.Column(db.Integer(), nullable=False, primary_key=True, )
    something = db.Column(db.String(100))
    json_document = db.Column(db.JSON())

so then I could do

db.session.add(Mytable(something="XYZ", 
                       json_documnet=json.dump({"p1":123})))
Marcin
  • 179
  • 2
  • 14
  • Due to the way their JSON support is built, you should have a look at this: ["Marshal JSON Strings"](https://docs.sqlalchemy.org/en/13/core/custom_types.html#marshal-json-strings). This is also relevant: https://stackoverflow.com/questions/4038314/sqlalchemy-json-as-blob-text – Ilja Everilä Oct 04 '19 at 15:41

0 Answers0