JSON

This is a wrapper for the json module: it will use simplejson if available, or the json module from Python >= 2.6 if available, and as a last resource the django.utils.simplejson module on App Engine.

It will also escape forward slashes and, by default, output the serialized JSON in a compact format, eliminating white spaces.

Some convenience functions are also available to encode and decode to and from base64 and to quote or unquote the values.

webapp2_extras.json.encode(value, *args, **kwargs)[source]

Serializes a value to JSON.

This comes from Tornado.

Parameters:
  • value – A value to be serialized.
  • args – Extra arguments to be passed to json.dumps().
  • kwargs – Extra keyword arguments to be passed to json.dumps().
Returns:

The serialized value.

webapp2_extras.json.decode(value, *args, **kwargs)[source]

Deserializes a value from JSON.

This comes from Tornado.

Parameters:
  • value – A value to be deserialized.
  • args – Extra arguments to be passed to json.loads().
  • kwargs – Extra keyword arguments to be passed to json.loads().
Returns:

The deserialized value.

webapp2_extras.json.b64encode(value, *args, **kwargs)[source]

Serializes a value to JSON and encodes it using base64.

Parameters and return value are the same from encode().

webapp2_extras.json.b64decode(value, *args, **kwargs)[source]

Decodes a value using base64 and deserializes it from JSON.

Parameters and return value are the same from decode().

webapp2_extras.json.quote(value, *args, **kwargs)[source]

Serializes a value to JSON and encodes it using urllib.quote or urllib.parse.quote(PY3).

Parameters and return value are the same from encode().

webapp2_extras.json.unquote(value, *args, **kwargs)[source]

Decodes a value using urllib.unquote or urllib.parse.unquote(PY3) and deserializes it from JSON.

Parameters and return value are the same from decode().

Previous topic

Jinja2

Next topic

Local

This Page