Skip to content

json.py

PydanticJSON dataclass

Bases: IO[BaseModel]

IO to load and save Pydantic models to JSON

Example usage:

>>> from pathlib import Path
>>> from ordeq_pydantic import PydanticJSON
>>> from pydantic import BaseModel

>>> class MyModel(BaseModel):
...     hello: str
...     world: str

>>> dataset = PydanticJSON(
...     path=Path("path/to.json"),
...     model_type=MyModel
... )

load()

Load the Pydantic model from the JSON file.

Returns:

Type Description
BaseModel

The loaded Pydantic model.

save(model)

Save the Pydantic model to a JSON file.

Parameters:

Name Type Description Default
model BaseModel

The Pydantic model to save.

required