import json


def create_diff_json(image_diff, file_output_name):
    """diff image file and save as file

    args:
        image_diff (object)
        file_output_name (str)

    returns:
        saved_file (str)
    """
    diff_content = {}
    for attr in image_diff.attributes:
        diff_content[attr] = {}
        diff_content[attr]["before"] = getattr(image_diff, attr)[0]
        diff_content[attr]["after"] = getattr(image_diff, attr)[1]
        if diff_content[attr]["before"] != diff_content[attr]["after"]:
            diff_content[attr]["diff"] = True
    diff_content["pixel"] = image_diff.pixel_diff
    with open(file_output_name + ".diff.json", "w") as diff_file:
        json.dump(diff_content, diff_file, indent=4)
    return file_output_name + ".diff.json"