Extendable JSON
Extendable JSON is an extendable drop in replacement of Python’s JSON library. By using @json_serialize and @json_deserialize decorators to enable custom objects not normally serializable by default.
This library includes the ability to serialize Exceptions, Objects, and Datetime objects by default.
Usage:
import extendable_json as json
json.dumps({"Key": "Value"})
outputs: “{“Key”: “Value”}” as string
import extendable_json as json
json.loads('"{"Key": "Value"}"')
outputs: {“Key”: “Value”} as dict
To extend serialization to objects not normally serializable or customize serialization of an object, decorate a function accepting a single value with @json_serialize.register giving the object to serialize with this function. Return a dict containing keys and values of the object.
@json_serialize.register(MyObject)
def serialize_my_object(val):
return {"Attrib": str(val.attrib)}
Reverse this by decorating a function accepting a single value with @json_deserialize.register. Using val as a dictionary, extract the serialized data into a new object loading with data from val. Return the newly created object.
@json_deserialize.register(MyObject)
def deserialize_my_object(val):
myObject = MyObject()
myObject.attrib = val['Attrib']
return myObject
Exceptions
Exceptions may be serialized or deserialized.
Exceptions may be serialized within try/except block
try:
# Exception thrown
except Exception as e:
import extendable_json as json
json.dumps(e)
Once deserialized exceptions may be raised and/or the Traceback is available with the traceback attr.
e = json.loads(exeption_json)
raise e #To raise exception
print(e.traceback) #To print traceback
API Reference
extendable_json.dump(obj, fp, *, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, cls=_JSONDecoder, indent=None, separators=None, default=None, sort_keys=False, **kw)
Use exactly as Python’s JSON.
Please note that using the cls kwarg will disable this library’s functionality
extendable_json.dumps(obj, *, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, cls=_JSONDecoder, indent=None, separators=None, default=None, sort_keys=False, **kw)
Use exactly as Python’s JSON.
Please note that using the cls kwarg will disable this library’s functionality
extendable_json.load(fp, *, cls=_JSONEncoder, object_hook=None, parse_float=None, parse_int=None, parse_constant=None, object_pairs_hook=None, **kw)
Use exactly as Python’s JSON.
Please note that using the cls kwarg will disable this library’s functionality
extendable_json.loads(s, *, cls=_JSONEncoder, object_hook=None, parse_float=None, parse_int=None, parse_constant=None, object_pairs_hook=None, **kw)
Use exactly as Python’s JSON.
Please note that using the cls kwarg will disable this library’s functionality
@extendable_json.json_serialize(object)
Decorator used to add objects to serialization registry. Please see above documentation on how to use.
@extendable_json.json_deserialize(object)
Decorator used to add objects to deserialization registry. Please see above documentation on how to use.
Indices and tables
-
Index
-
Module Index
-
Search Page
Metadata
Release files for Extendable-JSON 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| Extendable_JSON-0.0.1-py3-none-any.whl | Python 3 | none | any | Details for Extendable_JSON-0.0.1-py3-none-any.whl |
Release files / Extendable_JSON-0.0.1-py3-none-any.whl
| Download URL | Extendable_JSON-0.0.1-py3-none-any.whl |
|---|---|
| Size | 7.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3c3a9a95bdf039fb12a0575bd337775c4bf00b6ad9247c81c4d2f6bf6683cd53
|
|
BLAKE2b-256 checksum How to use checksums |
1ed36bc11e3a23a3039569afd44b8a6cbcdf949eff1cf29a294a0e33bca4e48b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2
|
Security for Extendable-JSON 0.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.