A
A
alegkonin2020-10-29 01:18:37
Flask
alegkonin, 2020-10-29 01:18:37

How to make sqlalchemy friends with json?

Good evening, I ask you to resolve a sore point. Own knowledge is not enough, and Google does not google (
There is a certain model

__tablename__ = 'organisations_address'
    id = db.Column(db.Integer, primary_key=True)
    area = db.Column(db.JSON, nullable=True)


insert into area
area = '{' + f"\"code\":\"{area_code}\", \"name\":\"{area_name}\"" + '}',


however, an escaped string is coming to the db : "{\"code\":\"string\"}"
i have already tried to just send the string : but sqlalchemy intentionally escapes any double quotes

Maybe someone practices this and can help?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
alegkonin, 2020-10-29
@alegkonin

Everything turned out to be very simple, thanks, the issue is resolved.

area = '{' + f"\"code\":\"{area_code}\", \"name\":\"{area_name}\"" + '}',

such fences did not need to be fenced at all, but to send dict

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question