import json # simple example id2label = {1: 'tree0', 2: 'tree1', 3:'tree3' } with open('trees_id2label.json', 'w') as fp: json.dump(id2label, fp)