JOSE protocol implementation in Python with support for JSON Web Algorithms, Keys, and Signatures
73
Model a contact profile object that maps attribute names to specific JSON keys, fills in defaults when fields are absent, and omits optional values when they are empty. Attribute to JSON key mapping must be: username -> user, email -> contact_email, timezone -> tz, phone -> phone, tags -> labels, and marketing_opt_in -> marketing_opt_in.
tz and marketing_opt_in yields a profile with timezone "UTC" and marketing_opt_in False; serializing the result with json_dumps includes those defaults along with the provided user and contact_email values. @testnull and labels array is empty on the Python object, both json_dumps and to_partial_json omit phone and labels entirely while still including required fields and the defaulted timezone. @test{"user": "ana", "contact_email": "ana@example.com", "phone": "+123", "tz": "Europe/Paris", "labels": ["vip"]}, loading to a profile and converting back to a dict via the JSON serialization API preserves all values and uses the same JSON keys. @test@generates
class ContactProfile:
def __init__(self, username: str, email: str, timezone: str = "UTC", phone: Optional[str] = None, tags: Optional[list[str]] = None, marketing_opt_in: bool = False): ...
@classmethod
def from_json(cls, jobj: Any) -> "ContactProfile": ...
@classmethod
def json_loads(cls, json_string: str) -> "ContactProfile": ...
def to_partial_json(self) -> dict: ...
def json_dumps(self, **kwargs) -> str: ...Provides declarative JSON object mapping with field defaults and omission of empty values during serialization.
Install with Tessl CLI
npx tessl i tessl/pypi-josepyevals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10