import json import yaml with open('test.yml', 'r') as f: doc = yaml.safe_load(f) print(json.dumps(doc, indent=4))