def METHOD_NAME(result):
    tests = []
    for test in result.tests:
        fail_reason = test.get("fail_reason", UNKNOWN)
        if fail_reason is not None:
            fail_reason = astring.to_text(fail_reason)
        # Actually we are saving the TestID() there.
        test_id = test.get("name", UNKNOWN)
        if isinstance(test_id, TestID):
            name = f"{test_id.name}{test_id.str_variant}"
        tests.append(
            {
                "id": str(test_id),
                "name": str(name),
                "start": test.get("time_start", -1),
                "end": test.get("time_end", -1),
                "time": test.get("time_elapsed", -1),
                "status": test.get("status", {}),
                "tags": test.get("tags") or {},
                "whiteboard": test.get("whiteboard", UNKNOWN),
                "logdir": test.get("logdir", UNKNOWN),
                "logfile": test.get("logfile", UNKNOWN),
                "fail_reason": fail_reason,
            }
        )
    content = {
        "job_id": result.job_unique_id,
        "debuglog": result.logfile,
        "tests": tests,
        "total": result.tests_total,
        "pass": result.passed,
        "errors": result.errors,
        "failures": result.failed,
        "skip": result.skipped,
        "cancel": result.cancelled,
        "warn": result.warned,
        "interrupt": result.interrupted,
        "time": result.tests_total_time,
        "start": str(result.job_start_date_time),
    }
    return json.dumps(content, sort_keys=True, indent=4, separators=(",", ": "))