-
-
Save luckylittle/d3fb9f493f1c0b5547390a1b26c3de78 to your computer and use it in GitHub Desktop.
Convert CloudFormation YAML format to JSON format
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 | |
import sys, yaml, json | |
def funcparse(loader, node): | |
node.value = { | |
yaml.constructor.ScalarNode: loader.construct_scalar, | |
yaml.constructor.SequenceNode: loader.construct_sequence, | |
yaml.constructor.MappingNode: loader.construct_mapping, | |
}[type(node)](node) | |
node.tag = node.tag.replace(u'!Ref', 'Ref').replace(u'!', u'Fn::') | |
return dict([ (node.tag, node.value) ]) | |
funcnames = [ 'Ref', 'Base64', 'FindInMap', 'GetAtt', 'GetAZs', 'ImportValue', | |
'Join', 'Select', 'Split', 'Split', 'Sub', 'And', 'Equals', 'If', | |
'Not', 'Or' ] | |
for func in funcnames: | |
yaml.SafeLoader.add_constructor(u'!' + func, funcparse) | |
json.dump(yaml.safe_load(sys.stdin), sys.stdout, indent=4) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment