Object-to-JSON
JSON serializer for class instances with minimal declaration overhead.
Features
- Attributes that represent object state are automatically detected
by checking
__init__argument names - Custom serializers for objects with complex state
- Automatic generation of
__eq__method
Usage
Installation
pip install objtojson
Example
from objtojson import Serialized
class SomeClass(Serialized):
def __init__(self, someAttribute, other):
self.someAttribute = someAttribute
self.other = other
class AnotherClass(Serialized):
def __init__(self, a, b):
self.a = a
self.b = b
a = SomeClass(4, [AnotherClass(['a', 'list'], {'mykey': 34}), 'somestring'])
print(a.Serialize())
Result:
{
"__someclass__": {
"someAttribute": 4,
"other": [
{
"__anotherclass__": {
"a": [
"a",
"list"
],
"b": {
"mykey": 34
}
}
},
"somestring"
]
}
}
Saving to file, loading from file
from objtojson import Serializer
Serializer.Save('data.json', a)
a_reloaded = Serializer.Load('data.json')
Restrictions
- Attribute names must match
__init__argument names - Tuples will be serialized/deserialized as lists
- Dict keys must be valid JSON object keys (i.e., strings)
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
objtojson-0.5.0.tar.gz
(4.3 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file objtojson-0.5.0.tar.gz.
File metadata
- Download URL: objtojson-0.5.0.tar.gz
- Upload date:
- Size: 4.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
deaba2693089e36110a4de11bd9a73c5a145ae2c0c90088dbb23720c933638cb
|
|
| MD5 |
0b9016cd0fc49daedfee3cb5ea250516
|
|
| BLAKE2b-256 |
031e729d8ac9e792b2c0e26d8c9d7440afe7056c9abaa773cfe6759f005f91be
|
File details
Details for the file objtojson-0.5.0-py3-none-any.whl.
File metadata
- Download URL: objtojson-0.5.0-py3-none-any.whl
- Upload date:
- Size: 4.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
68d3c87edd6001a113e5da92671969570f909c92689fc28ee0ecb74e265c7049
|
|
| MD5 |
b3d55bd3c5645571758150074d3990ae
|
|
| BLAKE2b-256 |
b568c64c18e887a2e0408a8a9b486df6c3c17fa67b6610fdd9fc01ce10f17b04
|