Deserialize Json activities - how to get separate information

im using this tip to get some info from a txt> https://docs.uipath.com/activities/docs/deserialize-json

but i dont know how to get specific itens inside the “0001”, i want to consult with deserialize json but i want this 3 infos in 3 differents variables, is that possible ? in the link, when i call cars, he get all the 3 infos in one string, how to split it
image

all 3 infos in the same string ><
image

Hi @Leonardo_Andreola

You can use:

yourJsonObject.SelectToken("YourFieldName").ToString

Hey Leonardo,

you could use a second Deserialize Json activity to split the contents of your token “0001” into tokens themselves.

Send the contents of your token “0001” into a Deserialize Json activity like this:
yourJsonObject.SelectToken("0001").ToString

Then get the separate information like this:
yourSecondJsonObject.SelectToken("value").ToString

It only gets tricky if you don’t know how deep the Json goes.
Hope this helps

1 Like

Lets try to understand you in amore clear way. A JsonObject defines a property “0001” and its value is a JSONObject again - lets refer to it with jo2

we do understand from you statement that it is unknown how many properties
jo2 does have, right?

give a try on following:

  • for each activity: item | values: yourJObjectVar(“0001”).Value(Of JObject).Properties | TypeArgument: JProperty

    • log message: item.Name & " - " & item.Value.toString

what is shown in the output?

yes, the problem with the first and second solution is that each item will have date, value and document type, but the “0001” will be different, my robot know “0001” number and need to give me the other 3 results, i was able to do then individually using a simple txt like this
{
“0001”:“01/01/2020”,
“0002”:“02/02/2020”
}
than the robot input the 0001 and output the date.
but i will have to do 3 differents txt and select the same token 3 times to do than, im trying to get all the info into one code
image

dont know if you get what i need, im using google translator here

@Leonardo_Andreola
Important is to respect the different structures and to have it included into the requirement / case description.

The approach for it is similar along with a nested loop:


Input / output:
grafik
grafik
kindly note the dynamics, showcased with the additional comment: ABC

Alternate

Parsing to a dictionary

Sometimes we want to Extract the data to a particular datastructure and here a Dictionary can help. The flow would look like this:

Output / Access Demo:
grafik

Deserializing to nested Dictionary

Doing similar to above (Parsing to a dictionary) we can do it directly within an assign

grafik
grafik

Find starter help here:

DynProps_ObjectExtraction_Log-Dict_Demo.xaml (10.0 KB)
JSON:
data.json (308 Bytes)

1 Like

Hi @Leonardo_Andreola,

You can use .SelectToken for all levels that you need:

jsonObj.SelectToken("0001").SelectToken("date").ToString()
jsonObj.SelectToken("0001").SelectToken("Document").ToString()
...
1 Like

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