Created
May 18, 2020 07:26
-
-
Save romgapuz/c7a4cedb85f090ac1b55383a58fa572c to your computer and use it in GitHub Desktop.
Tool for converting Pickle to JSON using this simple Python Command Line program
This file contains 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
""" | |
Pickle2JSON is a simple Python Command Line program for converting Pickle file to JSON file. | |
Arguments: Only one (1) argument is expected which is the pickle file. | |
Usage: python pickle2json.py myfile.pkl | |
Output: The output is a JSON file bearing the same filename containing the JSON document of the converted Pickle file. | |
""" | |
# import libraries | |
import pickle | |
import json | |
import sys | |
import os | |
# open pickle file | |
with open(sys.argv[1], 'rb') as infile: | |
obj = pickle.load(infile) | |
# convert pickle object to json object | |
json_obj = json.loads(json.dumps(obj, default=str)) | |
# write the json file | |
with open( | |
os.path.splitext(sys.argv[1])[0] + '.json', | |
'w', | |
encoding='utf-8' | |
) as outfile: | |
json.dump(json_obj, outfile, ensure_ascii=False, indent=4) |
Hi, I am trying to convert pickle object to RDS object, is there a way to convert json to RDS further, to give context, we are building GBM model in python so model object is getting saved as pickle, but due to legacy reasons we have to do deployment in R, looking for a way around here.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hello how can I convert pkl file to mesh.obj file ?