Created
May 29, 2024 19:33
-
-
Save doesitblend/6e63caf909235c4875bbf38b172b382f to your computer and use it in GitHub Desktop.
json_yaml_converter.py
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
#!/opt/saltstack/salt/bin/python3.10 | |
# This script was generated with ChatGPT | |
import sys | |
import json | |
import yaml | |
def main(): | |
try: | |
# Read JSON data from STDIN | |
input_data = sys.stdin.read() | |
# Parse JSON data | |
json_data = json.loads(input_data) | |
# Convert JSON to YAML | |
yaml_data = yaml.dump(json_data, default_flow_style=False) | |
# Output YAML data to STDOUT | |
sys.stdout.write(yaml_data) | |
except Exception as e: | |
# Output errors to STDERR | |
sys.stderr.write(str(e) + "\n") | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment