Converting Yaml cloudformation template to Json
AWS Console can help you with that. Open your CloudFormation template in template designer.
CloudFormation > Select your stack > Template > View in designer
You can then easily convert your template by choosing your template language as Json.
In case you wanted a command-line solution for converting from JSON to YAML and vice versa, consider the aws-cfn-template-flip project.
Install the library:
▶ pip install cfn_flip
Usage:
▶ cfn-flip
Usage: cfn-flip [OPTIONS] [INPUT] [OUTPUT]
AWS CloudFormation Template Flip is a tool that converts AWS
CloudFormation templates between JSON and YAML formats, making use of the
YAML format's short function syntax where possible.
Options:
-i, --input [json|yaml] Specify the input format. Overrides -j and -y
flags.
-o, --output [json|yaml] Specify the output format. Overrides -j, -y, and
-n flags.
-j, --json Convert to JSON. Assume the input is YAML.
-y, --yaml Convert to YAML. Assume the input is JSON.
-c, --clean Performs some opinionated cleanup on your
template.
-l, --long Use long-form syntax for functions when converting
to YAML.
-n, --no-flip Perform other operations but do not flip the
output format.
--version Show the version and exit.
--help Show this message and exit.
And if you have your CloudFormation template in a YAML then you can flip it to JSON using:
▶ cfn-flip -j cloudformation.yml | jq . > cloudformation.json
Use of the JQ there is optional, just to clean the formatting.
I use this and it works like a charm: https://cfnflip.com/
You can convert JSON to YAML and YAML to JSON.
Copy/Paste either, will detect and flip. Opensource and Source Code available if you want to set this up as your own internal too. (no, this is NOT mine nor sponsored).
This is not just a normal Flipping tool, this works specifically with CloudFormation in mind.