Define JSONType in schematics python
up vote
0
down vote
favorite
I have problem with python schematics. I am using PostgreSQL database, where one of my columns is of json type. From my code perspective I am using schematics to create Request, but schematics dont have JSONType. So I create StringType with json validator like this
param: StringType = StringType(validators=[json_validator])
Json validator looks like this:
def json_validator(data):
try:
json.loads(data)
return data
except ValueError:
raise ValidationError(u'Given parameter value is not JSON.')
When I insert data through PostgreSQL, there is no problem with json, but when I am trying to save data through postman with post request with body like this:
{
"param": "{"name": "John"}"
}
Saved data in db looks like this:
"{"name": "John"}"
Is there a way how to define JSONType in schematics or how to save json like this:
{"name": "John"}
to database?
python flask-sqlalchemy
add a comment |
up vote
0
down vote
favorite
I have problem with python schematics. I am using PostgreSQL database, where one of my columns is of json type. From my code perspective I am using schematics to create Request, but schematics dont have JSONType. So I create StringType with json validator like this
param: StringType = StringType(validators=[json_validator])
Json validator looks like this:
def json_validator(data):
try:
json.loads(data)
return data
except ValueError:
raise ValidationError(u'Given parameter value is not JSON.')
When I insert data through PostgreSQL, there is no problem with json, but when I am trying to save data through postman with post request with body like this:
{
"param": "{"name": "John"}"
}
Saved data in db looks like this:
"{"name": "John"}"
Is there a way how to define JSONType in schematics or how to save json like this:
{"name": "John"}
to database?
python flask-sqlalchemy
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have problem with python schematics. I am using PostgreSQL database, where one of my columns is of json type. From my code perspective I am using schematics to create Request, but schematics dont have JSONType. So I create StringType with json validator like this
param: StringType = StringType(validators=[json_validator])
Json validator looks like this:
def json_validator(data):
try:
json.loads(data)
return data
except ValueError:
raise ValidationError(u'Given parameter value is not JSON.')
When I insert data through PostgreSQL, there is no problem with json, but when I am trying to save data through postman with post request with body like this:
{
"param": "{"name": "John"}"
}
Saved data in db looks like this:
"{"name": "John"}"
Is there a way how to define JSONType in schematics or how to save json like this:
{"name": "John"}
to database?
python flask-sqlalchemy
I have problem with python schematics. I am using PostgreSQL database, where one of my columns is of json type. From my code perspective I am using schematics to create Request, but schematics dont have JSONType. So I create StringType with json validator like this
param: StringType = StringType(validators=[json_validator])
Json validator looks like this:
def json_validator(data):
try:
json.loads(data)
return data
except ValueError:
raise ValidationError(u'Given parameter value is not JSON.')
When I insert data through PostgreSQL, there is no problem with json, but when I am trying to save data through postman with post request with body like this:
{
"param": "{"name": "John"}"
}
Saved data in db looks like this:
"{"name": "John"}"
Is there a way how to define JSONType in schematics or how to save json like this:
{"name": "John"}
to database?
python flask-sqlalchemy
python flask-sqlalchemy
asked Nov 10 at 22:50
M. Barabas
144
144
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53244192%2fdefine-jsontype-in-schematics-python%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown