Giter Site home page Giter Site logo

json_validator's Introduction

json_validator


Decorator for validating json parameters passed to function. Can be used for validation of parameters sent to Flask and loaded by request.get_json().

Uses jsonschema for validating data.

Instalation

pip install json_validator

Parameters

Args:
    message: message returned in case of validation errors
    params_variable: name of the argument which contains json parameters
    schema_filename: name of json file or path to the json file in which
                        json schema is stored
    debug: if set to True, will raise detailed exception in case of validation errors

Returns:
    Returns {"status": message} in case of validation errors
    Returns function passed to decorator in case that validation passed

Decorator defaults

@validate_params(message="Wrong params!",
                 params_variable="params",
                 schema_filename="schema.json",
                 debug=False)

Usage Examples

You can find examples of usage in ./examples directory.

Below you can find simplest usage examples:

Example 1:

from json_validator import validate_params

@validate_params
def some_function(params):
    result = some_another_function(params)
    return result

Example 2:

from json_validator import validate_params

@validate_params(schema_filename="schema1.json",
                 params_variable="params_dict",
                 message="DENIED!",
                 debug=True)
def some_function(params_dict):
    result = some_another_function(params_dict)
    return result

Tests

  1. To test json_validator with default system python:
py.test
  1. To test multiple python versions on OS X use pyenv and tox:

a) prepare environment:

brew install pyenv
pyenv install -s 2.7.13
pyenv install -s 3.5.3
pyenv install -s 3.6.0
pyenv local 2.7.13 3.5.3 3.6.0

b) run tests:

tox

json_validator's People

Contributors

sliwinski-milosz avatar

Stargazers

brian avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.