Value in JSON for Key is shown as a single String

Hi All,

Am working on a process , I dont have any errors coming up in the XAML but the Value for Keys which have multiple values is shown as a single string.
Example :
expected for enr2 : [“Mem1”,
“La1”,
“xyz”,
“abc”,
“qwer”]

actual result for enr2:
“Mem1,La1,xyz,abc,qwer,jklm”

Main.xaml (16.1 KB)
sample.json (716 Bytes)

1 Like

Okay @Nandakishore_Reddy

You can just convert it to an array by string split.

str_Jval.Split(","c)

Hope this helps.

Thanks
#nK

Hi @Nithinkrishna could you please elaborate how and where to split because the data is coming from the data table.

1 Like

You are taking few rows or only the value you mentioned above ?

HI @Nithinkrishna,
I am taking all the rows in the data table.
The problem is with the Keys which have multiple values are taken as single string which should not be the case for my workflow which i attached earlier.

Could you please show the activity or code where you are retrieving that ?

I’m trying to understanding how you are trying to get and use it !

HI @Nithinkrishna,

when you run the Main.XAML, at the end in the log message you would see that value for enr1 is shown as a single string

attaching the screenshot at the output.

1 Like

So now what do you want to do with that ENR2 value ?

enr2 should be looking like enr2: [“Mem1”,“La1”,“xyz”,“abc”,“qwer”,“jklm”] instead of a single string as its shown in the previous screenshot.

Okay @Nandakishore_Reddy

So you wanna change in the json itself ?

@Nithinkrishna
Yes in the final JSON the values should be how I described earlier.

Okay @Nandakishore_Reddy

  1. De-serialize your JSON into a JObject (De-serialize Activity)

  2. And then access that enr2 key from JObject to change it back (Assign Activity)

jObj("enr2") = Newtonsoft.Json.JsonConvert.SerializeObject(jObj("enr2").ToString.Split(" "c))

Hope this helps

Thanks
#nK

thanks for your PM

it looks like you want to set a JArray like
grafik

which will result to:

when value comes e.g. from excel like: A,B so we can create the string array e.g. with the split method:
grafik

thanks @ppr,
Can you elaborate on where exactly do we make the changes in my xaml … I am new to Uipath dont have much information on how to implement the changes

In my actual process I have many keys which have multiple values and doing assign myJObject(“enr2”)=JArray.FromObject({“Mem1”,“La1”,“xyz”,“abc”,“qwer”,“jklm”}) for each key might be difficult. Also these values are not constant , its not same always. Could you please suggest for my XAML how do i go about implementing it.

@ppr Any suggestions on the requirement or if you can help me with the updated XAML which give us the desired results.
As i said many keys would have multiple array of values so changing each key might not work for my process.

kindly note: we shared a snippet to demonstrate on how the general implementation block would look like. As we can see from the screenshot the JSON was updated as requested ["A","B"]

For sure you will adapt it and dynamize it.

we do feel that your case description needs some more elaboration and we would recommend to follow the pattern: All inputs, case description, expected output description. This would help us for guiding you on a solution approach

Thanks for the update.

I did try the myJobject(“enr2”) = JArray.FromObject({“Mem1”,“La1”,“xyz”,“abc”,“qwer”,“jklm”})
But my Json object might have other keys Eq: e1: j1,j2,j3 . So we might be able to use assign activity for everytime manually putting in he values.
As for the XAML i shared my process includes updating a JSON with the values from an excel. I had created a sample XAML which involves the following steps:
1.Datatable has key and value column which has the Key Value Pairs
2. Another Datatable for mapping the key values
3. Read Text file activity to read the JSON data.
4. Deserialize the JSON file
5. Assigned dictKLValues =dtData.AsEnumerable.ToDictionary(Of String, Object)(Function (x) x(“Key”).toString, Function (x) x(“Value”))
6. Looop through the Mapping Datatable to update the values using Invoke method.

The expected output for all the Keys which have multiple values is as shown below:
“enr2”: [

    "Mem1",
    "La1",
    "xyz",
    "abc",
    "qwer"
]

whereas we get it as “enr2”:“Mem1,La1,xyz,abc,qwer,jklm”
This is not the expected result. I wanted help modifying my XAML accordingly which would give me the expected result. Once this is sorted the complete update JSON would be pasted in a internal WebPage.

I hope this gives a gist of my requirement.
Please do let me know if any further information is required.