given a simple example of
from pydantic import BaseModel
class UserModel(BaseModel):
name: str
id: int
data : List[UserModel] = [{id:1,name:'bob'},{id:1,name:'mary}]
how do i validate with pydantic for data such that id cannot be duplicated in the List?
First off, your data is not in a proper format, the keys must be string like:
You can use the
AfterValidationalong with aTypeAdapter.output:
You can further improve the
check_uniquenessfunction to report which keys are the same to the user.