Package s3 :: Module s3validators :: Class IS_JSONS3
[frames] | no frames]

Class IS_JSONS3

source code

gluon.validators.Validator --+
                             |
                            IS_JSONS3


Similar to web2py's IS_JSON validator, but extended to handle
single quotes in dict keys (=invalid JSON) from CSV imports.

Example:

    INPUT(_type='text', _name='name', requires=IS_JSONS3())

    >>> IS_JSONS3()('{"a": 100}')
    ({u'a': 100}, None)

    >>> IS_JSONS3()('spam1234')
    ('spam1234', 'invalid json')

Instance Methods
 
__init__(self, native_json=False, error_message="Invalid JSON")
Constructor
source code
 
__call__(self, value)
Validator, validates a string and converts it into db format
source code
 
formatter(self, value)
Formatter, converts the db format into a string
source code
Method Details

__init__(self, native_json=False, error_message="Invalid JSON")
(Constructor)

source code 

Constructor

Parameters:
  • native_json - return the JSON string rather than a Python object (e.g. when the field is "string" type rather than "json")
  • error_message - the error message

__call__(self, value)
(Call operator)

source code 

Validator, validates a string and converts it into db format

formatter(self, value)

source code 

Formatter, converts the db format into a string