Skip to content

Instantly share code, notes, and snippets.

@prashanthpai
Created February 23, 2022 05:01
Show Gist options
  • Save prashanthpai/4e8aa6fc05f1a335176576f1a2d08ff2 to your computer and use it in GitHub Desktop.
Save prashanthpai/4e8aa6fc05f1a335176576f1a2d08ff2 to your computer and use it in GitHub Desktop.
Convert a json file to toml file using Python
#!/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