import json
import logging


def dict_to_json(metrics, input_filepath):
    """ Outputs metrics dictionary as a JSON file with the same name (and
    directory) as the original csv file from the beginning of the pipeline.

    :param metrics: Dictionary of metrics
    :param input_filepath: The filepath of the inputted csv
    :return: String representing filepath of new JSON file
    """
    json_filepath = input_filepath[:-3] + "json"
    with open(json_filepath, "w") as file:
        json.dump(metrics, file)
    logging.info("JSON file written: %s" % json_filepath)
    return json_filepath