from typing import Iterator
from typing import Mapping
import json
import time


def json_failure_handler(results: Iterator[Mapping]) -> str:
    """A failure handler which returns results in a JSON-formatted response.

   Args:
        results: The results of all checks which were executed for a checker.
            Each result dictionary is guaranteed to have the keys: 'check',
            'message', 'passed', 'timestamp'.

    Returns:
        The checker response, formatted as JSON.
    """
    return json.dumps({
        'status': 'failure',
        'timestamp': time.time(),
        'results': results,
    })