import json


def _parse_request_body(request):
    """Parse the JSON from the request body, or return its bytes"""
    body = request.body
    if not body:
        return b''

    if request.headers.get("Content-Type") == "application/json":
        if isinstance(body, bytes):
            return json.loads(body.decode())
        return json.loads(body)

    if isinstance(body, str):
        return body.encode()
    return body