Passing string variable to get value from Jobject

Hello fellow automation enthusiasts,
I am having issues with a propably simple error.

As input i have a .json file.
I’m using the “Read Text File” activity to read and store it as a String.
I then, using the “Deserialize JSON” activity, generate a JObject.
This works. So far, so good.
Now if i want to select a specific Value from JObject i could use a statement like:
Jobject("identifications")(0)("identificationStatus")("status").ToString
This also works! Wuhu!

Now comes the part that doesnt work.
I need to pass (“identifications”)(0)(“identificationStatus”)(“status”) as a string variable.
For example:

tmp_Key = “(”“identifications”")(0)("“identificationStatus”")("“status”")"
Jobject(tmp_Key).ToString

This returns the following error message

RemoteException wrapping System.NullReferenceException: Object reference not set to an instance of an object.

Im assuming it has something to do with not correctly escaping quotes. I’ve fiddled with different ways using " instead of “”. But nothing worked.

I’m grateful for every suggestions on how to fix this.
Thank you!

@Moritz_Kuehnau
welcome to the forum

Jobject("identifications")(0)("identificationStatus")("status").ToString
navigates through the different elements till the status property

Jobject(“(”“identifications”")(0)("“identificationStatus”")("“status”")") looks fo a long key (which not exists) but is not doing the navigation. Therfore no element is returned

Hi Peter,
thanks for the quick response!
Is there a way to navigate and retrieve elements using a string variable or am i fighting a loosing battle?

@Moritz_Kuehnau
give a try on working with selectToken:
grafik

Thanks for the hint Peter!
Using selectToken with the following String

$.identifications.[0].identificationStatus.status

worked like a charm!
Thank you for the fast help and have a nice day! =)

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.