I would recommend a python library called DictShield for this https://github.com/j2labs/dictshield
DictShield is a database agnostic modeling system. This makes it easy to model, validate and modify data.
There is even a sample for checking JSON:
User input validation
Let's say we get this JSON string from the user.
{"bio": "Python, Erlang and guitars!", "secret": "e8b5d682452313a6142c10b045a9a135", "name": "J2D2"}
We could write server code that looks like this:
json_string = request.get_arg('data') user_input = json.loads(json_string) user.validate(**user_input)
source share