# retoor <retoor@molodetz.nl>

import json


def parse_metadata(raw: str | dict | None) -> dict | None:
    if not raw:
        return None
    if isinstance(raw, dict):
        return raw
    try:
        return json.loads(raw)
    except (ValueError, TypeError):
        return {"raw": str(raw)}
