Skip to main content

A simple converter from complex objects to JSON

Project description

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}]}]}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

serialiJSON-0.0.2.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

serialiJSON-0.0.2-py2.py3-none-any.whl (3.6 kB view details)

Uploaded Python 2Python 3

File details

Details for the file serialiJSON-0.0.2.tar.gz.

File metadata

  • Download URL: serialiJSON-0.0.2.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for serialiJSON-0.0.2.tar.gz
Algorithm Hash digest
SHA256 e541644d0869f5f153627a5e0a5447026206f09211f968016d803837d4064f24
MD5 12b8aa52c10918b6a66a5e4f495c9b65
BLAKE2b-256 090d4735f3d078972a7c1bf547118dd33136593bcbb811e477323e98fa467352

See more details on using hashes here.

File details

Details for the file serialiJSON-0.0.2-py2.py3-none-any.whl.

File metadata

  • Download URL: serialiJSON-0.0.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 3.6 kB
  • Tags: Python 2, Python 3
  • Uploaded using 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

File hashes

Hashes for serialiJSON-0.0.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 652dd45a94daded23c83cdafd4fc15a2090e1a79a6b1d3f8dd6683a56878de74
MD5 1bab5f9ad2395b6fc17336f5d93625b5
BLAKE2b-256 6928917927c9420dc1564479e9f25543ae44602e12da9a89562aa43c1acb8147

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page