Fetching just a particular part of a json row

Hey all, my last step for my script makes me stuck. I recieve the following json:

“status”: “success”,
“activeActivations”: [
{
“activationId”: “1624962258”,
“serviceCode”: “ot”,
“phoneNumber”: “37065199434”,
“activationCost”: “15.00”,
“activationStatus”: “2”,
“smsCode”: [
“Your Orderd verification number is: 3522”
],
“smsText”: [
“Your Orderd verification number is: 3522”

I need to fetch the number from the line: “Your Orderd verification number is: 3522”

So in this case only the 3522

I just red a few other threads but as I´m a bloody beginner i guess i will need further help.

I know I will get super quick responses from you and want to thank you in advance.

We fixed the snippet ot make it as a valid JSON and deserilized it - out: myJObject
grafik

Samples:
grafik
1st: access
2nd: Regex for the number extraction

HEy thanks for ur replay.

Deserilization is already done. I just wanted to show the value i want to fetch.

I really have no experience with regex. How to do it and how to implant?

Hi @Hugen_Dugen

Use the below regular expression to extract the required data from the input.

(?<=Your Orderd verification number is\:\s+)\d+

Hope it helps!!

HEy ty for replay. i guess i have to use an assign function for this right?

1 Like

the shown samples were done within the immediate panel:

Assign activity:
myValue | DataType String = myJObject(“activeActivations”)(0)(“smsCode”)(0).Value(Of String)

myCode | DataType String =
System.Text.RegularExpressions.Regex.Match(myValue, "(?<=: )\d+").Value

Also have a look here:

Yes @Hugen_Dugen

You have to use assign for this

- Assign -> MatchVar = System.Text.RegularExpressions.Regex.Matches(yourstringinput.ToString,“((?<=Your Orderd verification number is\:\s+)\d+)”)

In the above assign MatchVar is a Ienumerable of Matches datatype variable.
In the place of yourstringinput.ToString provide the String variable which has the input text.

After this take an one more assign activity. Then create a variable to change Ienumerable of matches to text as below.

- Assign -> Output = MatchVar(0).toString

Or

With out using assign you can use another activity called find matching patterns activity to get the output by using regex.

You can copy the above regex expression and paste it in the find matching pattern activity by changing to advance. You can pass the input data string variable. Create a variable in output by ctrl+k. Then take an assign activity after that to take the output as string.

- Assign -> Output = MatchVar(0).toString

Output has to be String datatype variable.

Hope it helps!!

Kindly note:

  • as a single match is needed Match can be used instead of Matches
  • the return of a Matches method is MatchCollection
    grafik
1 Like

@ppr yeah sure I’ll do note of it.

Hi @Hugen_Dugen

You can simply try this

1.Use Deserialise JSON activity
2.Use Assign activity

VerificationNumber=myJObject(“activeActivations”)(0)(“smsCode”)(0).Value(Of String)

Regards,

Thank u can u give me little hint what i have to input here

:VerificationNumber=myJObject(“activeActivations”)(0)(“smsCode”)(0).Value(Of String)

@Hugen_Dugen

Verification number is the String datatype variable.
In the save to field of assign activity create a variable called verification number. In the value to field of assign activity give the remaining expression. Like below

- Assign -> VerificationNumber=myJObject(“activeActivations”)(0)(“smsCode”)(0).Value(Of String)

After this also you have to use the above regular expressions to get the required output. Here you are saving one object into a variable.

Hope you understand!!

@Hugen_Dugen

First take Deserialize JSON activity create a output variable of that activity as myJObject
then take assign activity

VerificationNumber=myJObject(“activeActivations”)(0)(“smsCode”)(0).Value(OfString)

ty I did the desterilization already.

But as in ur Screenshot i have the expression mark as well. So there is an error isnt it?

@Hugen_Dugen

Try this

myJObject(“activeActivations”)(0)(“smsCode”). ToString

If that is not working please try this

JSONObject("activeActivations")(0)("smsCode")(0).ToString().Split(":"c)(1).Trim()

Tried but this occures

@Hugen_Dugen

Can u please provide json file

Try this

myJObject(“activeActivations”)(0)(“smsCode”)(0).Value(Of int32)

DUgen.txt (1.4 KB)

Of Course. Thank u for ur hel appreciate it.

With the Value Method we grab the value as string
As we get
grafik
we got more then only the number

After using regex we get the number as string:
grafik

when the extracted number string is needed as an int we can do
myCodeAsInt | DataType: int32 = CInt(myCode )
grafik