from typing import Any
from pydantic import BaseModel  # noqa: E0611
import json


def response_to_json(response: Any):
    """
    Converts a response to a json string

    :param response: A List[Any] or Dict[Any, Any] or a Pydantic model,
        that should be converted to a valid json string
    :return: A json string representation of the response
    """
    if isinstance(response, list):
        return [response_to_json(val) for val in response]
    elif isinstance(response, dict):
        return {key: response_to_json(val) for key, val in response.items()}
    elif isinstance(response, BaseModel):
        return response.dict()
    return json.dumps(response)