Convenience scripts for converting from yaml to json. Currently my usecase is writing AWS CloudFormation templates in YAML and then converting them to JSON for the upload to AWS.
Two implementations are included: Ruby and Python.
The advantage of writing CloudFormation templates in YAML over JSON is that YAML allows for comments. Also, in my option, YAML is far for readable than JSON. Since CloudFormation requires JSON, it's convenient to develop to YAML and then convert to JSON right before uploading.
If you would like to contribute another language, please fork and open a PR.
yaml_to_json.py < cf.yaml > cf.cftemplate
aws cloudformation create --template-body file://cf.cftemplate
Some common CloudFormation functions are non-obvious in YAML. The following are quick conversions.
JSON | YAML |
"Fn::GetAtt": [ "MyLoadBalancer", "DNSName" ] |
Fn::GetAtt: - MyLoadBalancer - DNSName |
"Fn::Join": [ "delimiter", [ comma-delimited, list, of, values ] ] |
Fn:Join: - delimiter - - comma-delimited - list - of - values |
"Fn::FindInMap:" [ "EbsOptimizedMap", { "Ref": "InstanceType" }, "Optimized" ] |
Fn::FindInMap: - EbsOptimizedMap - Ref: InstanceType - Optimized |