因為最近都在寫AWS CloudFormation,所以會接觸到大量的json以及yaml範本。

但json在閱讀上真的是很眼花撩亂…

所以找到了一個非常偉大的工具!

cfn-flip

這個python套件在使用上非常的簡單明瞭。

安裝:

pip3 install cfn_flip

使用方法:

    ~ » 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.

直接Demo~

弱弱這邊準備了一個簡單的111.json檔案如下圖:

Alt flip-1

接著就直接下 cfn-flip 111.json,他就會直接轉換,如圖二

Alt flip-2

如果要輸出為yaml檔的話,也可以利用 -i -o來做處理:

Alt flip-3

有這麼方便的工具,在看一些json檔就可以不用這麼辛苦了!