Created
October 1, 2023 07:26
-
-
Save sonnyksimon/bf0fc5350bfb238bf03766e1ada5e034 to your computer and use it in GitHub Desktop.
yaml2json: Compact script for yaml to json conversion
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 | |
"""yaml2json: Compact script for yaml to json conversion""" | |
import yaml | |
import json | |
import sys | |
args = [open(x,'r') for x in sys.argv[1:]] | |
args = [sys.stdin.read(), *args] if not sys.stdin.isatty() else args | |
files = [yaml.safe_load(y) for y in args] | |
out = files[0] if len(files) == 1 else files | |
sys.stdout.write(json.dumps(out,separators=(',',':'))) |
Author
sonnyksimon
commented
Oct 1, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment