Skip to content

Instantly share code, notes, and snippets.

@Luigi-Pizzolito
Created February 10, 2024 21:56
Show Gist options
  • Save Luigi-Pizzolito/3c21d5bffb544b37196b82d77644496b to your computer and use it in GitHub Desktop.
Save Luigi-Pizzolito/3c21d5bffb544b37196b82d77644496b to your computer and use it in GitHub Desktop.
Convert a Python PickleDB into JSON format for using in other languages.
import pickledb
import json
def convert_pickle_to_json(pickle_file, json_file):
# Load the pickle database
db = pickledb.load(pickle_file, False)
# Extract data from the database
data = {}
for key in db.getall():
data[key] = db.get(key)
# Convert data to JSON format
json_data = json.dumps(data, indent=4)
# Write JSON data to a file
with open(json_file, 'w') as f:
f.write(json_data)
if __name__ == "__main__":
pickle_file = "cmu_ipa.pickle"
json_file = "cmu_ipa.json"
convert_pickle_to_json(pickle_file, json_file)
print(f"Pickle database '{pickle_file}' converted to JSON file '{json_file}'.")
@Luigi-Pizzolito
Copy link
Author

Originally used to convert https://people.umass.edu/nconstan/CMU-IPA/ from https://github.com/yokolet/transcript Pickle format to JSON.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment