Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
solution using re.sub() solution in Clear category for YAML. More Types by ddavidse
import re
def yaml(inp):
a = [x for x in inp.split('\n') if x]
D0 = {x.split(':')[0] : x.split(':')[1].strip().replace('\\','') for x in a}
D = D0.copy()
for key in D.keys():
subbed = re.sub(r'^\"(.*)\"$', r'\1', D[key])
D[key] = subbed
if not (subbed.capitalize() == 'Null' and subbed != D0[key]):
if D[key].isnumeric():
D[key] = int(D[key])
elif D[key].capitalize() == 'False':
D[key] = False
elif D[key].capitalize() == 'True':
D[key] = True
elif not D[key] or D[key].capitalize() == 'Null':
D[key] = None
return D
Jan. 20, 2021