Skip to content

Conversation

@AlexSamarsky
Copy link

i want to load json with key name 'from', make dataclasse with field "from_" and load it if config.reserved_names is True
i found that nessesary when worked with JIRA API
it returns change history json

    data = {
                "field": "IssueParentAssociation",
                "fieldtype": "jira",
                "from": "88223",
                "fromString": "PRJ-1",
                "to": "88222",
                "toString": "PRJ-2"
              }

then make dataclass

@dataclass
class HistoryItemJson:
    field: str
    fieldtype: str
    fieldId: Optional[str]
    from_: Optional[str]
    fromString: Optional[str]
    to: Optional[str]
    toString: Optional[str]

and simply load it
result: HistoryItemJson = from_dict(data_class=HistoryItemJson, data=data, config=Config(type_hooks={datetime: datetime.fromisoformat}, reserved_names=True))

Samarskiy_A_S added 2 commits February 17, 2023 19:01
… json with name from, make dataclasse with field from_ and load it if reserved_names is True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant