Dictionary in Yaml to dictionary in UiPath

Hi there,
I would like to use a content of dictionary in Yaml “config” file to fill in a dictionary in UiPath. I use C# syntax.

Yaml file looks like this:

I have initialized a dictionary in UiPath

And also tried to directly relate to config file like that:

but now I’m lost how to make it all work.

Would be really grateful for your help. :slight_smile:

A combination of Regex and LINQ can help.

Can you share with us the Value of Config(“tourDeFranceWinners”)

as text file or here formatted with the </> Button?

I can’t debug it as there is a validation error:

As we will help ypu on this step you can remove or comment out
Feel free to take the value within alternate way e.g. the config source

the dictionary config[“tourDeFranceWinners”] should contain:

this we already got this from above (no repetition is needed).
You can speedup things, when providing us it as text. Thanks for support

In general a flow would look like following:

  • Regex catching year/winners into groups
  • LINQ toDictionary with the required Lambdas to key and value

[CheatSheet] - System.Text.RegularExpressions | RegEx - News / Tutorials - UiPath Community Forum

[HowTo] LINQ (VB.Net) Learning Catalogue - Help / Something Else - UiPath Community Forum

2006: “Oscar Pereiro”
2007: “Alberto Contador”
2008: “Carlos Sastre”
2009: “Alberto Contador”
2010: “Andy Schleck”

Sorry for misunderstanding :slight_smile:

I thought there could be a way to directly read a dictionary from Yaml (because it is in Yaml dictionary format) as a dictionary in UiPath, but may try with regexes.

in general we prefer to process XML with XML tools, JSOn with JSON tools… and would also prefer YAML processing with YAML tools

But YAML is very, very sensitive on spaces, tabs, linebreaks.

Thats why we are selecting the alternate (otherwise research by your own offered YAML parsers)

Give us a little time we will come back with a suggestion

1 Like

 	2006: ""Oscar Pereiro""
   2007: ""Alberto Contador""
     2008: ""Carlos Sastre""
 2009: ""Alberto Contador""
  2010: ""Andy Schleck"""
 myMatches = Regex.Matches(strText, strPattern)
 MatchCollection(5) { [2006: "Oscar Pereiro], [2007: "Alberto Contador], [2008: "Carlos Sastre], [2009: "Alberto Contador], [2010: "Andy Schleck] }
 myMatches.Cast(Of Match).ToDictionary(Function (m) Cint(m.Groups(1).Value), Function (m) m.Groups(3).Value)
 Dictionary<int, string>(5) { { 2006, "Oscar Pereiro" }, { 2007, "Alberto Contador" }, { 2008, "Carlos Sastre" }, { 2009, "Alberto Contador" }, { 2010, "Andy Schleck" } }

ensure that System.Text.RegularExpressions is added to the imports as described also within the CheatSheet

Tank you @ppr!

I also managed to invoke the dictionary directly from Yaml :slight_smile:

tourDeFranceWinners = config[“tourDeFranceWinners”].ToObject<Dictionary<int,string>>()

when config is as JSON then it would have properator seperators within the entries right?
can you show us this?

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.