Deserialize a YAML "Table" of data
All of these are valid YAML files. You are however mistaking interpreting a scalar key with commas as constituting a description in YAML of the "columns" in the sequences of the value associated with that key.
In File 1, FirstName, LastName, Age, Height
is a single string scalar key for the mapping that is the first element of the sequence that is value for the key Group
at the top level. Just like name
is. You can, but don't have to in YAML, put quotes around the whole scalar.
The association you make between a string "Firstname" and "Joe" is not there in YAML, you can make that association in the program that interprets the key (by splitting it on ", "
) as you seem to be doing, but YAML has no knowledge of that.
So if you want to be smart about this, then you need to split the string "FirstName, LastName, Age, Height"
yourself and use some mechanism to then use the "subkeys" to index the sequences that are associated with the key.
If it helps to understand all this, the following is a json dump of the first files' contents, there you see clearly what the keys consist of:
{"Groups": [{"FirstName, LastName, Age, Height": [["Joe", "Soap", 21,
184], ["Mary", "Ryan", 20, 169], ["Alex", "Dole", 24, 174]],
"Name": "ATeam"}]}
I used the Python based ruamel.yaml
library for this (of which I am the author) but you could also use an online convertor/checker like http://yaml-online-parser.appspot.com/