JSON
JSON Serialization is the most common serialization format used in the KVDB
library. It is a good choice for serializing data that will be sent over the network or stored in a file, and is customized to provide serialization of most data types and objects.
Additionally, it can be customized to use sub-libraries such as simdjson
, orjson
, ujson
, and the standard json
library.
References
JSON Encoder Utility
The following function is called to support the JSON serialization of objects:
Helper to serialize an object
PARAMETER | DESCRIPTION |
---|---|
obj
|
the object to serialize
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
typing.Union[typing.Dict[str, typing.Any], typing.List[typing.Dict[str, typing.Any]], typing.Any]
|
the serialized object in dict |
typing.Union[typing.Dict[str, typing.Any], typing.List[typing.Dict[str, typing.Any]], typing.Any]
|
{ "type": ..., "value": ..., |
typing.Union[typing.Dict[str, typing.Any], typing.List[typing.Dict[str, typing.Any]], typing.Any]
|
} |
Source code in kvdb/io/serializers/utils.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
|
API Reference
Bases: kvdb.io.serializers.base.BaseSerializer
METHOD | DESCRIPTION |
---|---|
adecode |
Decodes the value asynchronously |
adumps |
Dumps the value asynchronously |
aencode |
Encodes the value asynchronously |
aloads |
Loads the value asynchronously |
check_encoded_value |
Check the encoded value to remove the prefix |
compress_value |
Compresses the value |
copy |
Copies the serializer |
create_hash |
Creates a hash for the object |
decode |
Decodes the value |
decode_one |
Decode the value with the JSON Library |
decode_value |
Decode the value with the JSON Library |
decompress_value |
Decompresses the value |
deprecated_decompress_value |
Attempts to decompress the value using the deprecated compressor |
dumps |
Dumps the value |
encode |
Encodes the value |
encode_value |
Encode the value with the JSON Library |
fetch_object_classname |
Fetches the object classname |
loads |
Loads the value |
set_default_lib |
Sets the default JSON library |
ATTRIBUTE | DESCRIPTION |
---|---|
compression_enabled |
Returns if compression is enabled
TYPE:
|
compression_level |
Returns the compression level
TYPE:
|
Source code in kvdb/io/serializers/_json.py
adecode
async
adecode(
value: typing.Union[str, bytes],
schema_map: typing.Optional[
typing.Dict[str, str]
] = None,
raise_errors: typing.Optional[bool] = None,
**kwargs
) -> kvdb.io.serializers.base.ObjectValue
Decodes the value asynchronously
Source code in kvdb/io/serializers/_json.py
adumps
async
aencode
async
aloads
async
check_encoded_value
Check the encoded value to remove the prefix
Source code in kvdb/io/serializers/_json.py
compress_value
Compresses the value
Source code in kvdb/io/serializers/base.py
copy
copy(**kwargs) -> kvdb.io.serializers.base.BaseSerializer
Copies the serializer
Source code in kvdb/io/serializers/base.py
create_hash
decode
decode(
value: typing.Union[str, bytes],
schema_map: typing.Optional[
typing.Dict[str, str]
] = None,
raise_errors: typing.Optional[bool] = None,
**kwargs
) -> kvdb.io.serializers.base.ObjectValue
Decodes the value
Source code in kvdb/io/serializers/_json.py
decode_one
decode_one(value: str, **kwargs) -> typing.Union[
kvdb.io.serializers.base.SchemaType,
typing.Dict,
typing.Any,
]
Decode the value with the JSON Library
Source code in kvdb/io/serializers/_json.py
decode_value
decode_value(
value: str,
schema_map: typing.Optional[
typing.Dict[str, str]
] = None,
raise_errors: typing.Optional[bool] = None,
**kwargs
) -> typing.Union[
kvdb.io.serializers.base.SchemaType,
typing.Dict,
typing.Any,
]
Decode the value with the JSON Library
Source code in kvdb/io/serializers/_json.py
decompress_value
Decompresses the value
Source code in kvdb/io/serializers/base.py
deprecated_decompress_value
deprecated_decompress_value(
value: typing.Union[str, bytes], **kwargs
) -> typing.Optional[typing.Union[str, bytes]]
Attempts to decompress the value using the deprecated compressor
Source code in kvdb/io/serializers/base.py
dumps
Dumps the value
Source code in kvdb/io/serializers/base.py
encode
encode_value
encode_value(
value: typing.Union[
typing.Any, kvdb.io.serializers.base.SchemaType
],
**kwargs
) -> str
Encode the value with the JSON Library
Source code in kvdb/io/serializers/_json.py
fetch_object_classname
loads
Loads the value
Source code in kvdb/io/serializers/base.py
set_default_lib
classmethod
set_default_lib(
lib: typing.Union[
str,
kvdb.io.serializers._json.JsonLibT,
kvdb.io.serializers.base.ModuleType,
]
) -> None
Sets the default JSON library