Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for YAML. More Types by ET_N_Lai
def yaml(a):
d=dict()
aList=a.split('\n')
value2=''
for i in aList:
if len(i)==0:
continue
if len(i)>1:
key=i[0:i.index(":")]
value=i[i.index(":")+1:].strip()
if value.startswith('"') and value.endswith('"'):
value2=value[1:-1]
value2=value2.replace('\\','')
else:
value2=value
if value.isdigit():
value2=int(value)
if value=='false' :
value2=False
if value=='' :
value2=None
if value=='null' :
value2=None
d[key]=value2
return d
print ((yaml('name: Alex\nage: 12') ))
print ((yaml('name: Alex Fox\n' 'age: 12\n' '\n' 'class: 12b') ))
print ((yaml('name: "Alex \\"Fox\\""\n'
'age: 12\n'
'\n'
'class: 12b')) )
print (yaml('name: \"Bob Dylan\"\nchildren: 6\ncoding: \"null\" '))
print (yaml('\nname: Alex\nage: 12'))
Sept. 2, 2020