Package Products :: Package ZenUtils :: Module jsonutils
[hide private]
[frames] | no frames]

Module jsonutils

source code

Classes [hide private]
StringifyingDecoder
Casts all unicode objects as strings.
JavaScript
A simple class that represents a JavaScript literal that should not be JSON encoded.
JavaScriptRegex
A simple class that represents a JavaScript Regex literal that should not be JSON encoded.
JavaScriptEncoder
A JavaScript encoder based on JSON.
Functions [hide private]
 
_recursiveCaster(ob) source code
str, func
json(value, **kw)
Serialize value into a JSON string.
source code
 
javascript(data)
A JavaScript encoder based on JSON.
source code
 
unjson(value, **kw)
Create the Python object represented by the JSON string value.
source code
Function Details [hide private]

json(value, **kw)

source code 

Serialize value into a JSON string.

If value is callable, a decorated version of value that serializes its return value will be returned.

>>> value = (dict(a=1L), u"123", 123)
>>> print json(value)
[{"a": 1}, "123", 123]
>>> @json
... def f():
...     return value
...
>>> print f()
[{"a": 1}, "123", 123]
Parameters:
  • value (dict, list, tuple, str, etc. or callable) - An object to be serialized
Returns: str, func
The JSON representation of value or a decorated function

javascript(data)

source code 

A JavaScript encoder based on JSON. It encodes like normal JSON except it passes JavaScript objects un-encoded.

unjson(value, **kw)

source code 

Create the Python object represented by the JSON string value.

>>> jsonstr = '[{"a": 1}, "123", 123]'
>>> print unjson(jsonstr)
[{'a': 1}, '123', 123]
Parameters:
  • value (str) - A JSON string
Returns:
The object represented by value