import json


def dict2json(to_json, output):  # Tested [N]
    """
    Wrapper for `json` package to easily turn python dictionaries into JSON files on disk.

    Used to create files to pass to the create_features_script for computing ratios and subtractions.

    Args:
        to_json (dict): Dictionary to serialize into JSON
        output (str): Path to save the output JSON file

    Returns:
        (bool) True if saving to JSON was successful, False otherwise.
    """
    try:
        with open(output, 'w') as f:
            json.dump(to_json, f)
        return True

    except Exception as e:
        print(e)
        return False