Package SPARQLWrapper :: Module jsonlayer
[hide private]
[frames] | no frames]

Module jsonlayer

source code

Thin abstraction layer over the different available modules for decoding and encoding JSON data.

This module currently supports the following JSON modules:

The default behavior is to use ``simplejson`` if installed, and otherwise fallback to the standard library module. To explicitly tell SPARQLWrapper which module to use, invoke the `use()` function with the module name:

   import jsonlayer
   jsonlayer.use('cjson')

In addition to choosing one of the above modules, you can also configure SPARQLWrapper to use custom decoding and encoding functions:

   import jsonlayer
   jsonlayer.use(decode=my_decode, encode=my_encode)
Functions [hide private]
 
decode(string)
Decode the given JSON string.
source code
 
encode(obj)
Encode the given object as a JSON string.
source code
 
use(module=None, decode=None, encode=None)
Set the JSON library that should be used, either by specifying a known module name, or by providing a decode and encode function.
source code
 
_initialize() source code
Variables [hide private]
  _initialized = False
  _using = None
hash(x)
  _decode = None
hash(x)
  _encode = None
hash(x)
  __package__ = None
hash(x)
Function Details [hide private]

decode(string)

source code 

Decode the given JSON string.

:param string: the JSON string to decode :type string: basestring :return: the corresponding Python data structure :rtype: object

encode(obj)

source code 

Encode the given object as a JSON string.

:param obj: the Python data structure to encode :type obj: object :return: the corresponding JSON string :rtype: basestring

use(module=None, decode=None, encode=None)

source code 

Set the JSON library that should be used, either by specifying a known module name, or by providing a decode and encode function.

The modules "simplejson", "cjson", and "json" are currently supported for the ``module`` parameter.

If provided, the ``decode`` parameter must be a callable that accepts a JSON string and returns a corresponding Python data structure. The ``encode`` callable must accept a Python data structure and return the corresponding JSON string. Exceptions raised by decoding and encoding should be propagated up unaltered.

:param module: the name of the JSON library module to use, or the module object itself :type module: str or module :param decode: a function for decoding JSON strings :type decode: callable :param encode: a function for encoding objects as JSON strings :type encode: callable