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

classDiagram class DataclassJSONEncoder { }

Documentation

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

Class that extends json.JSONEncoder to support encoding dataclasses and pydantic models

default(obj)

Encodes 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)

Serializes an object to JSON using DataclassJSONEncoder.

Parameters:
  • data (Any) – The object to serialize to JSON.

  • **kwargs

    Additional keyword arguments to pass to the json.dumps method.

Returns:

str – A JSON string representation of the object.