# This file was auto-generated by Fern from our API Definition.
# Heavily modified to prevent recursion errors completely

from __future__ import annotations

import typing
from typing import Any, Dict, List, Optional, Union

# IMPORTANT: Completely non-recursive version of JSON type
# Using Any to prevent any possibility of recursion
FullJsonOutput = Union[str, int, float, bool, Dict[str, Any], List[Any], None]


# No recursive types at all
def sanitize_json(value: Any) -> Any:
    """Convert potentially recursive structures to safe non-recursive ones"""
    if isinstance(value, dict):
        return {k: sanitize_json(v) for k, v in value.items()}
    elif isinstance(value, list):
        return [sanitize_json(item) for item in value]
    elif hasattr(value, "model_dump"):
        # It's a Pydantic V2 model
        return sanitize_json(value.model_dump())
    elif hasattr(value, "dict"):
        # It's a Pydantic V1 model
        return sanitize_json(value.dict())
    else:
        # Primitive value
        return value
