Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
lstrip, rstrip, replace solution in Clear category for YAML. More Types by kkkkk
def yaml(yaml_text):
"""Convert yaml_text into an object."""
json_dict = {}
for line in yaml_text.split("\n"):
if not line:
continue
tag, value = line.split(':')
value = value.strip()
# Digit?
if value.isdigit():
value = int(value)
# Boolean?
elif "true" in value:
value = True
elif "false" in value:
value = False
# Empty value?
elif not value or value == 'null':
value = None
else:
# String?
value = value.lstrip('"')
if value[-1] == '"':
value = value[:-1]
value = value.replace('\\"', '"')
json_dict[tag.strip()] = value
return json_dict
Nov. 7, 2019