import json


def data_from_request(request):
    """Return a dict of data from a JSON request, idempotent."""
    if isinstance(request, dict):
        return request
    raw = request.get_data().decode('utf-8')
    return json.loads(raw or '{}')