Skip to content
Discussion options

You must be logged in to vote

In general the approach is to use item.model_dump(exclude_unset=True), then iterate through keys and update values of JSON:

@app.patch("/items/{item_id}", response_model=Item)
async def update_item(item_id: str, item: Item):
    json_data = ... # Read JSON file.

    update_data = item.model_dump(exclude_unset=True)
    for key, value in update_data.items():
        json_data[key] = value

    return json_data # and return a updated json file. 

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by YuriiMotov
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question or problem question-migrate
2 participants
Converted from issue

This discussion was converted from issue #4788 on February 27, 2023 22:03.