Starting with Python 3.7, there is something called a dataclass:
from dataclasses import dataclass @dataclass class Foo: x: str
However, t
Can't you just use the dataclasses.asdict() function to convert the dataclass to a dict? Something like:
dataclasses.asdict()
>>> @dataclass ... class Foo: ... a: int ... b: int ... >>> x = Foo(1,2) >>> json.dumps(dataclasses.asdict(x)) '{"a": 1, "b": 2}'