Convert a dataclass structure to a JSON object
Project description
Dataclass_to_json
Dataclass_to_json is a lightweight and simple library for Converting a dataclass structure to a JSON object. The dataclass_to_json library allows you to retrieve a JSON object representing the class attributes and their types.
Installing Dataclass_to_json
dataclass_to_json in available on PyPI:
python -m pip install dataclass_to_json
Dataclass_to_json officially supports Python 3.7+.
Usage
from dataclass_to_json import dataclass_to_json
from typing import List
import json
class Employee:
name: str
age: int
salary: float
remarks: List[str]
class Entreprise:
name: str
address: str
employees: List[Employee]
json_structure = dataclass_to_json(Entreprise)
print(json.dumps(json_structure, indent= 2))
The output:
{
"name": "str",
"address": "str",
"employees": [
{
"name": "str",
"age": "int",
"salary": "float",
"remarks": [
"str"
]
}
]
}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for dataclass_to_json-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a7c383a48668c11d1d2f376bfab46840d8739f3b6ec66ff8454df38dfaf4d12d |
|
MD5 | 55f6cc71dc62c21925588ad4229e11fc |
|
BLAKE2b-256 | 06844380b054f8f0f8a8a8fa46d53d7c9df15969af1e79b288f70f9a771d78dd |