JSONCodec
¶
digraph inheritancee6d6bf04cd {
bgcolor=transparent;
rankdir=UD;
ratio=compress;
size="8.0, 12.0";
"Codec" [color=dodgerblue1,fillcolor=white,fontcolor=black,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.5,shape=box,style=rounded,tooltip="The base class for all codecs"];
"Logger" -> "Codec" [arrowsize=0.5,style="setlinewidth(0.5)"];
"JSONCodec" [color=dodgerblue1,fillcolor=white,fontcolor=black,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.5,shape=box,style=rounded,tooltip="A codec able to encode/decode to/from json format. It uses the"];
"Codec" -> "JSONCodec" [arrowsize=0.5,style="setlinewidth(0.5)"];
"Logger" [color=dodgerblue1,fillcolor=white,fontcolor=black,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.5,shape=box,style=rounded,tooltip="The taurus logger class. All taurus pertinent classes should inherit"];
"Object" -> "Logger" [arrowsize=0.5,style="setlinewidth(0.5)"];
"Object" [color=dodgerblue1,fillcolor=white,fontcolor=black,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.5,shape=box,style=rounded];
}
-
class
JSONCodec
[source]¶ Bases:
taurus.core.util.codecs.Codec
A codec able to encode/decode to/from json format. It uses the
json
module.Example:
>>> from taurus.core.util.codecs import CodecFactory >>> cf = CodecFactory() >>> codec = cf.getCodec('json') >>> >>> # first encode something >>> data = { 'hello' : 'world', 'goodbye' : 1000 } >>> format, encoded_data = codec.encode(("", data)) >>> print encoded_data '{"hello": "world", "goodbye": 1000}' >>> >>> # now decode it >>> format, decoded_data = codec.decode((format, encoded_data)) >>> print decoded_data {'hello': 'world', 'goodbye': 1000}
-
decode
(data, *args, **kwargs)[source]¶ decodes the given data from a json string.
- Parameters
data (
sequence[str, obj]
) – a sequence of two elements where the first item is the encoding format of the second item object- Return type
sequence[str, obj]
- Returns
a sequence of two elements where the first item is the encoding format of the second item object
-
encode
(data, *args, **kwargs)[source]¶ encodes the given data to a json string. The given data must be a python object that json is able to convert.
- Parameters
data (
sequence[str, obj]
) – a sequence of two elements where the first item is the encoding format of the second item object- Return type
sequence[str, obj]
- Returns
a sequence of two elements where the first item is the encoding format of the second item object
-