Created
February 10, 2024 21:56
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}'.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Originally used to convert https://people.umass.edu/nconstan/CMU-IPA/ from https://github.com/yokolet/transcript Pickle format to JSON.