mnos
(Mnos)
August 25, 2022, 9:18am
1
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.
ppr
(Peter Preuss)
August 25, 2022, 9:26am
2
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?
mnos
(Mnos)
August 25, 2022, 9:34am
3
I can’t debug it as there is a validation error:
ppr
(Peter Preuss)
August 25, 2022, 9:35am
4
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
mnos
(Mnos)
August 25, 2022, 9:39am
5
the dictionary config[“tourDeFranceWinners”] should contain:
ppr
(Peter Preuss)
August 25, 2022, 9:44am
6
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
mnos
(Mnos)
August 25, 2022, 9:49am
7
tourDeFranceWinners:
2006: “Oscar Pereiro”
2007: “Alberto Contador”
2008: “Carlos Sastre”
2009: “Alberto Contador”
2010: “Andy Schleck”
Sorry for misunderstanding
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.
ppr
(Peter Preuss)
August 25, 2022, 9:54am
8
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
ppr
(Peter Preuss)
August 25, 2022, 10:27am
9
strText
@"tourDeFranceWinners:
2006: ""Oscar Pereiro""
2007: ""Alberto Contador""
2008: ""Carlos Sastre""
2009: ""Alberto Contador""
2010: ""Andy Schleck"""
strPattern
"(\d{4})(.*?)(?<=\\")(.*)(?=\\")"
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
mnos
(Mnos)
August 25, 2022, 11:19am
10
Tank you @ppr !
I also managed to invoke the dictionary directly from Yaml
tourDeFranceWinners = config[“tourDeFranceWinners”].ToObject<Dictionary<int,string>>()
ppr
(Peter Preuss)
August 25, 2022, 11:22am
11
@mnos
when config is as JSON then it would have properator seperators within the entries right?
can you show us this?
system
(system)
Closed
August 28, 2022, 11:23am
12
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.