Created
February 23, 2022 05:01
-
-
Save prashanthpai/4e8aa6fc05f1a335176576f1a2d08ff2 to your computer and use it in GitHub Desktop.
Convert a json file to toml file using Python
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
#!/usr/bin/env python | |
# Prerequisite: | |
# pip install toml | |
import json | |
import sys | |
import toml | |
def json_to_toml(json_file, toml_file): | |
with open(json_file) as jf: | |
with open(toml_file, 'w') as tf: | |
tf.write( | |
toml.dumps( | |
json.loads( | |
jf.read() | |
) | |
) | |
) | |
if __name__ == '__main__': | |
if len(sys.argv) != 3: | |
sys.exit('Usage: `json2toml.py input.json output.toml`') | |
json_file, toml_file = sys.argv[1], sys.argv[2] | |
json_to_toml(json_file, toml_file) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment