from typing import Any
import json


def parse_as_json_if_possible(v: str) -> Any:
    """Parse a string value as json if possible, but fallback to the string if not."""
    if isinstance(v, str):
        try:
            return json.loads(v)
        except json.JSONDecodeError:
            pass
    return v