from typing import Any
import json


def _handle_values_for_overrides_list(v: Any) -> Any:
    """
    Handle the special massaging of some values of JSON need to for it to be supplied
    to Hydra's overrides list.
    """
    # python's None --> cmd line null for override list
    v = "null" if v is None else v

    # if value is a dict, convert it to string to work with override list.
    # dump twice to escape quotes correctly.
    v = json.dumps(json.dumps(v)) if type(v) is dict else v
    # escape = char in value when present
    v = v.replace(r"=", r"\=") if type(v) is str else v
    return v