jsondataclasses package#

Module contents#

jsondataclasses.jsondataclass(cls: type) type[source]#

Returns the same class that is passed in, with a special __init__ method added to construct an instance of the class from a dictionary structure that complies with the class annotations

@jsondataclass
class Car:
    colour: str = jsonfield("colour")
    number_of_wheels: int = jsonfield("numberOfWheels")
jsondataclasses.jsonfield(key: str, parser: Callable[[Any], Any] | None = None, *, default_value: Any | None = None) tuple[str, Optional[Callable[[Any], Any]], Any][source]#
Parameters:
  • key – The key in the dictionary to pick

  • parser – Function that takes in a single value and returns a value of the desired type

  • default_value – If the key is not found in the json object, the default value will be passed to the parser instead