Turning data in YAML file to list/property list

Hi Team,

I have a configuration file written in yaml. Example of the structure will be as follow:
test-id: 1
test-name: “Test Case 1”
category: “functional Test”
test-option: “NA”

Question:
Is there a way to transform the data in YAML to list / property list in eggplant functional?
or is there a better way to read line by line from yaml file in eggplant?

Thank you

This will create a list of property lists:

put the number of lines of file(ResourcePath("config.yml")) into myLineCount

put myLineCount/4 into myBlockCount

put 0 into myBlockIterator

set myPropertyList to []

repeat myBlockCount times
	insert line (myBlockIterator +1) of file(ResourcePath("config.yml")) & comma & line (myBlockIterator +2) of file(ResourcePath("config.yml")) & comma & line (myBlockIterator +3) of file(ResourcePath("config.yml")) & comma & line (myBlockIterator +4) of file(ResourcePath("config.yml")) after myPropertyList
	set myBlockIterator = myBlockIterator + 4
end repeat

wait 5

Hope this helps,
Dave

1 Like

You could also try using the split operator to convert the yaml to a property list:

set yaml to {{
test-id: 1
test-name: "Test Case 1"
category: "functional Test"
test-option: "NA"

}}

put yaml split by return and ": " into plist

repeat with each [key, val] of plist
	set plist.(key) to value(val)
end repeat

put plist

I added the repeat loop to apply the value() function to each of the values in the property list in order to remove the quotes around the values. The value of a numeric value is just the number, but if there are other values in the list that aren’t quoted this may not be the right approach.

1 Like

Hi @SenseTalkDoug , @DaveHester ,

Thank you for the response and suggestion. Both are working perfectly.

Thank you
Best Regards,
Siti

1 Like