JSON Converter
The vibe_core.data.json_converter
module provides utility functions and classes for working with JSON serialization and deserialization of dataclasses and Pydantic models. This module simplifies the process of converting dataclasses and Pydantic models to JSON format and back, streamlining the management and organization of data in FarmVibes.AI.
Hierarchy
Documentation
JSON serialization/deserialization utilities.
- class vibe_core.data.json_converter.DataclassJSONEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)
Bases:
JSONEncoder
Extend json.JSONEncoder to support encoding dataclasses and pydantic models.
- default(obj)
Encode a dataclass or pydantic model to JSON.
- Parameters:
obj (Any) – The object to encode.
- Returns:
The JSON representation of the object.
- vibe_core.data.json_converter.dump_to_json(data, **kwargs)
Serialize an object to JSON using
DataclassJSONEncoder
.- Parameters:
data (Any) – The object to serialize to JSON.
**kwargs (Any) – Additional keyword arguments to pass to the json.dumps method.
- Returns:
A JSON string representation of the object.
- Return type:
str