Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add possibility use keywords from reserved names. #220

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

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