def boolean(value):
    """
    Parse the string ``"true"`` or ``"false"`` as a boolean (case insensitive).

    Also accepts ``"1"`` and ``"0"`` as ``True``/``False`` (respectively).

    If the input is from the request JSON body, the type is already a native python boolean,
    and will be passed through without further parsing.

    :raises ValueError: if the boolean value is invalid
    """
    if isinstance(value, bool):
        return value

    if value is None:
        raise ValueError("boolean type must be non-null")
    elif not value:
        return False
    value = str(value).lower()
    if value in ("true", "1", "on",):
        return True
    if value in ("false", "0",):
        return False
    raise ValueError("Invalid literal for boolean(): {0}".format(value))