Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for YAML. More Types by _Chico_
BOOLS = ['false', 'true']
def yaml(a):
obj = {}
for line in a.splitlines():
split_index = line.find(':')
if split_index != -1:
name, val_str = line[:split_index].strip(), line[split_index + 1:].strip()
if val_str.startswith('"') and val_str.endswith('"'):
value = val_str[1:-1].replace('\\"', '"')
elif val_str in BOOLS:
value = bool(BOOLS.index(val_str))
elif val_str.isdigit():
value = int(val_str)
elif val_str == 'null' or not val_str:
value = None
else:
value = val_str
obj[name] = value
return obj
June 5, 2021