import json import pickle for location in ["artists", "covers"]: alls = {} with open("/home/user/.mpd/"+location+".pk", "rb") as f: alls = pickle.load(f) allj = json.dumps(alls) with open("/home/user/.mpd/"+location+".json", "w") as f: f.write(allj)