import json


def planet_filter_cloud_from_json(json_file):
    """ Helper function for planet data cloud filtering from JSON

    Parameters
    ----------
    json_file: str
        `json_file` is the absolute or relative path to the *.json metadata file
        associated with the planet image

    Returns
    -------
    cloud_value: float
        `cloud_value` is a percent value 0-100 of the cloud coverage in the planet image

    Notes
    -----
    The cloud value is a percent 0-100 that is returned as a float.
    This function is a helper function to planet_filter_cloud

    """
    with open(json_file) as f:
        json_obj = json.load(f)
        # The json_obj is read similiarly as a python dictionary
        # aka json_obj.get("properties").get("cloud_cover")
        cloud_value = json_obj["properties"]["cloud_cover"]
    f.close()
    return float(cloud_value)