let me explain my issue. I have an string like this:
xxxxxxxx // xxxxxxxxx // yyyyyyyyyy // xxxxxx // xxxxx // yyyyyyyyyy // yyyyyyyyyy //
I want convert it to Json, but is not the problem. The problem is that I want to group them by the “[number]”. I would need something like this:
So the problem is basically how can I group them by the value “[number]”. All the rest is fine (quotes, commas, tabs, etc.)
Any idea about this?
Thank you very much friends.
Actually I got this Json format, maybe its worth to work with this instead work with the original String:
after deserialization will look like this:
you will lose some values.
We can achieve it by grouping the values, but need the detail input string. Maybe you can share it as txt file with us? Thanks
I was able to Get the Data into the Json as Needed. Although there might be a better method than this.
First we have to identify the group of values in the input String. We could use the below Regex for that :
We can then use the
Matches Activity with the above pattern to get the resultant matched values.
Here onwards, the data I have converted to a Datatable for ease in grouping the values.
Next, Group the data based on Number and iterate through the Grouped Values and add the Jobject or JArray as needed in the loop to a parent JObject.
Output would be in the Below format :
Check the workflow and Let us know if this doesn’t work :
ConvertString_ToJson.xaml (13.0 KB)
Thank you for the help. Here is the .txt input file.
inputText.txt (257 Bytes)
Thank you very much. Gonna try it and mark it as solution if I’m able to work with it. That’s exactly what I was thinking but I dont master REGEX. Lucky I find someone who does
@supermanPunch is almost perfect. Well, it is really perfect but I’ve made a mistake don’t telling you that the String has blank spaces
To explain me better, the initial string is not like “xxxxxxx”… is like “xxxx xxxxx xxxx xxxx xxx”, so using your .xaml i got this result
Could we fix this? Thank you again sir.
Try Replacing the Regular expression Pattern in
Matches Activity with the below :
Let us know if it doesn’t work
With the help of Regex we can split the string
refering to the groups (we will trim later)
For regex learning have a look here:
This CheatSheet introduces the basic use of regex functions. With further examples also special cases are presented.
From the namespace System.Text.RegularExpressions following methods are offered:
A simple usage for example would look like this:
add System.Text.RegularExpressions to the imports:
it allows to use the shortened statement, as the namespace part can be ommited…
With following flow we can achieve the result:
The main idea is about:
use regex to as mentioned above
Regex.Matches(strText, strPattern, RegexOptions.IgnoreCase)
group the matches and create JProperties, return all as an array
(From m In myMatches.Cast(Of Match).toList
Group m By k=m.Groups(1).Value.Trim Into grp = Group
Let arrVal = grp.Select(Function (a) a.Groups(2).Value.Trim).toArray
Let ja = JArray.FromObject(arrVal)
Select p = New JProperty(k, ja)).toarray
Create the JObject from the returned JProperty Array
We had used LINQ:
But can also decompose the LINQ part to essential activities
Find starter help here:
ppr_RegexBox_PabloSanchez.xaml (7.0 KB)
Thank you very much guys, I wish I could give 2 solutions xD
That’s what makes UiPath big… its community!
Thanks thanks and thanks
Have a nice day guys.
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.