from typing import Union
import json


def _parse_doc(doc: Union[str, dict]) -> dict:
    """Parse policy document if necessary.

    Args:
        doc: Policy document to parse.

    Returns:
        Parsed policy document.
    """

    if isinstance(doc, (str, bytes)):
        return json.loads(doc)

    return doc