Skip to content

This is a Flask Plugin to be used for Validate JSON request data.

License

Notifications You must be signed in to change notification settings

machine-w/flask-validate-json

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

flask-validate-json

This is a Flask Plugin to be used for Validate JSON request data.

This package uses jsonschema to for validation: https://pypi.python.org/pypi/jsonschema

jsonschema documentation: https://json-schema.org/understanding-json-schema/index.html

Usage

This package provides a flask route decorator to validate json payload.

from flask import Flask,g
from flask_validate_json import validate_json


app = Flask(__name__)

schema = {
    'type': 'object',
    'properties': {
        'name': {'type': 'string'},
        'email': {'type': 'string'},
        'password': {'type': 'string'}
    },
    'required': ['email', 'password']
}


@app.route('/register', methods=['POST'])
@validate_json(schema)
def register():
    # if payload is invalid, request will be aborted with error code 400
    # if payload is valid it is stored in g.json_data

    # do something with your data
    # example: user = User().from_dict(g.json_data)

About

This is a Flask Plugin to be used for Validate JSON request data.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages