Conversion of collection to dictionary

Hi,
I am trying to read JSON data as mentioned below:
“ColMapping”:
{
“A”:“B”,
“D”:“A”,
“C”:“C”
}

I would like to read this and convert to dictionary e.g. key is A and value is B
I encountered method ToDictionaryto convert it to dictionary - jsonData.Item(“ColMapping”).ToDictionary() but cannot proceed ahead. How do we pass parameters to ToDictionary? UiPath does not accept lambda expression. MSDN says this method accepts lambda expression. Can somebody guide me how to use ToDictionary in UiPath?

That’s partially true (depends on how you look at it). Lambda’s are a no, but anonymous functions are ok (do note that UiPath uses VB.Net for expressions, not C#).

That said, something like JsonConvert.DeserializeObject(Of DIctionary(Of String, String))(jsonData.Item("ColMapping") should work as an rvalue of an assign.
Short sample attached (not exactly your scenario, but should help).
Do note that you need to include Newtonsoft.Json namespace for it, or fully qualify the JsonConvert call.
JsonDictionaryTest.xaml (6.9 KB)

Regards.

1 Like

thanks.It worked like this in my case:

jsonData.Item(“ColMapping”).ToDictionary(Of String, String)(Function(k) k.ToString().Split({“:“c}).ElementAt(0).Replace(””“”,“”), Function(v) v.ToString().Split({":"c}).ElementAt(1))

2 Likes