import json
from typing import (
    Optional,
)

from xml.etree import cElementTree as eTree


def get_tender_detail(
    tender_line,  # type: eTree.Element
):
    # type: (...) -> Optional[str]

    tender_detail_json = tender_line.get("tenderDetail")
    if not tender_detail_json:
        return None

    try:
        tender_detail = json.loads(tender_detail_json)
    except TypeError:
        return None

    for value in tender_detail.keys():
        if tender_detail[value] is None:
            tender_detail[value] = ""
    return json.dumps(tender_detail)
