SerialiJSON
serialiJSON is a tool that allows you to convert complex objects to JSON only by inheriting the BaseSerializable class.
Installation
python pip -m install serialiJSON
Usage
Import BaseSerializable class
from serialiJSON import BaseSerializable
Define your own class inheriting BaseSerializable
class myClass(BaseSerializable):
...
myObject = myClass()
Convert to JSON
myObject.toJson()
An optional indent can be passed into toJson()
| Property | Description | type | default |
|---|---|---|---|
| indent | set the indent to pretty-printed | Int | None (most compact) |
Compatible Types
| Type | List mode |
|---|---|
| str | [str] |
| int | [int] |
| bool | [bool] |
| float | [float] |
Real Example
from serialiJSON import BaseSerializable
class Item(BaseSerializable):
def __init__(self, itemName, isAlive):
self.itemName = itemName
self.isAliva = isAlive
class Pet(BaseSerializable):
def __init__(self, name, age, favItems):
self.name = name
self.age = age
self.favItems = favItems
class Human(BaseSerializable):
def __init__(self, name, age, pets):
self.name = name
self.age = age
self.pets = pets
items = [
Item("snow ball", False),
Item("tree", True)
]
pets = [
Pet("Cat", 12, items),
Pet("Dog", 4, items)
]
human = Human("name", 90, pets)
print(human.toJson(indent=4))
pretty-printed
{
"name": "name",
"age": 90,
"pets": [
{
"name": "Cat",
"age": 12,
"favItems": [
{
"itemName": "snow ball",
"isAliva": false
},
{
"itemName": "tree",
"isAliva": true
}
]
},
{
"name": "Dog",
"age": 4,
"favItems": [
{
"itemName": "snow ball",
"isAliva": false
},
{
"itemName": "tree",
"isAliva": true
}
]
}
]
}
non pretty-printed
{"name": "name", "age": 90, "pets": [{"name": "Cat", "age": 12, "favItems": [{"itemName": "snow ball", "isAliva": false}, {"itemName": "tree", "isAliva": true}]}, {"name": "Dog", "age": 4, "favItems": [{"itemName": "snow ball", "isAliva": false}, {"itemName": "tree", "isAliva": true}]}]}
Metadata
Release files for serialiJSON 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| serialiJSON-0.0.2.tar.gz | 3.3 kB | Without provenance | Details for serialiJSON-0.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| serialiJSON-0.0.2-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details for serialiJSON-0.0.2-py2.py3-none-any.whl |
Total release size: 6.9 kB
Release files / serialiJSON-0.0.2.tar.gz
| Download URL | serialiJSON-0.0.2.tar.gz |
|---|---|
| Size | 3.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e541644d0869f5f153627a5e0a5447026206f09211f968016d803837d4064f24
|
|
BLAKE2b-256 checksum How to use checksums |
090d4735f3d078972a7c1bf547118dd33136593bcbb811e477323e98fa467352
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7
|
Release files / serialiJSON-0.0.2-py2.py3-none-any.whl
| Download URL | serialiJSON-0.0.2-py2.py3-none-any.whl |
|---|---|
| Size | 3.6 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
652dd45a94daded23c83cdafd4fc15a2090e1a79a6b1d3f8dd6683a56878de74
|
|
BLAKE2b-256 checksum How to use checksums |
6928917927c9420dc1564479e9f25543ae44602e12da9a89562aa43c1acb8147
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7
|
Security for serialiJSON 0.0.2
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.