Functions
- pyswark.lib.pydantic.ser_des.toJson(model: Type[BaseModel], **kw) str
Serialize a Pydantic model to JSON with embedded type information.
The serialized output includes the model’s fully-qualified class name, enabling automatic deserialization via
fromJson().- Parameters:
model (BaseModel) – A Pydantic model instance to serialize.
**kw – Additional keyword arguments passed to
json.dumps()(e.g.,indent=2for pretty-printing).
- Returns:
JSON string with structure:
{"model": "module.Class", "contents": {...}}- Return type:
str
See also
Example
>>> json_str = toJson(my_model, indent=2)
- pyswark.lib.pydantic.ser_des.fromJson(loadable: str) Type[BaseModel]
Deserialize JSON to its original Pydantic model type.
The JSON must have been created with
toJson()(or have the same structure withmodelandcontentskeys).- Parameters:
loadable (str) – JSON string containing embedded type information.
- Returns:
An instance of the original model class.
- Return type:
- Raises:
TypeError – If the
modelpath cannot be resolved or is not a BaseModel subclass.
Example
>>> restored = fromJson(json_string) >>> print(type(restored).__name__) 'Character'