Last active
July 23, 2023 16:08
-
-
Save glarrain/28f843109c5629e9bed257dd788810eb to your computer and use it in GitHub Desktop.
Python script to load a JSON file and print its contents converted to YAML.
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
#!/usr/bin/env python3 | |
"""Load a JSON file and print its contents converted to YAML. | |
Based on: | |
- https://stackoverflow.com/questions/15941996/dump-json-into-yaml/28506011#28506011 | |
- https://gist.github.com/sbp/985889 | |
""" | |
import json | |
import sys | |
import yaml | |
def load_json_from_file(filename: str): | |
with open(filename, 'r') as f: | |
parsed_json = json.load(f) | |
return parsed_json | |
def main(input_filename): | |
parsed_content = load_json_from_file(input_filename) | |
print(yaml.dump(parsed_content)) | |
if __name__ == '__main__': | |
input_filename = sys.argv[1] | |
main(input_filename) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment