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

# Module json

source code

Functions | [hide private]
str, func |
json(value) Serialize `value` into a JSON string. | source code
unjson(value) Create the Python object represented by the JSON string `value`. | source code

Function Details | [hide private]

### json(value) | 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

### unjson(value) | 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`