import json
from typing import OrderedDict


def validate_payload(payload):
    """Validate that the payload is of type OrderedDict.
    If the payload is of type str, then it assumes that the string is
    able to be parsed via json.

    Args:
        payload (str or OrderedDict): Payload object

    Returns:
        OrderedDict: Original payload object as an OrderedDict.

    """
    if isinstance(payload, str):
        payload = json.JSONDecoder(
            object_pairs_hook=OrderedDict
        ).decode(payload)
    if not isinstance(payload, OrderedDict):
        raise TypeError("Payload must be of type OrderedDict.")
    return payload