Simple-Notes icon indicating copy to clipboard operation
Simple-Notes copied to clipboard

backup file schema

Open andrew-karppinen opened this issue 1 year ago • 0 comments

The schema of the backup .json file has apparently changed at some point(?), and the old format is not compatible with the current version. Here is a Python script that can be used to convert the old backup file to the current format

import json


def transform_dict_list(dict_list):
    transformed_list = []
    
    for original_dict in dict_list:
        new_dict = {
            "path": "",
            "protectionHash": "",
            "protectionType": -1,
            "title": original_dict.get("title", ""),
            "type": 0,
            "value": original_dict.get("value", "")
        }
        transformed_list.append(new_dict)
    
    return transformed_list



def read_json_file(file_path):
    with open(file_path, 'r', encoding='utf-8') as file:
        data = json.load(file)
    return data

def save_dict_list_to_json(dict_list, file_path):
    with open(file_path, 'w', encoding='utf-8') as file:
        json.dump(dict_list, file, ensure_ascii=False, indent=4)




if __name__ == "__main__":


    file_path = 'old_backup.json' #old backup file path


    data = read_json_file(file_path) #read file to dict

    transformated_data =  transform_dict_list(data) #transformate data to new json schema


    save_dict_list_to_json(transformated_data,"backup.json") #save data to .json file



andrew-karppinen avatar Jun 28 '24 11:06 andrew-karppinen