How can I extract some values from a JSON file?

Hi,

I want to extrat different values corresponding to the next keys: nes, nis and numPolicy. Sometimes these values are inside the JSON file and, if this is the case, i want to get them and store them in a variable.

If been trying deserializing the JSON but i have not achieved any progress :frowning:

I attach an example of how the JSON files look like:

{
“process”: “liquidation”,
“salesforceCase”: “sales-1234”,
“salesforceId”: “slfid-001”,
“mailBox”: “juan@gmail.com”,
“expedient”: “exp-001”,
“documentId”: “doc-001”,
“documentName”: “mail-doc-001-1670224778775”,
“result”: [
{
“pages”: [
1
],
“categories”: [
{
“category”: “mail”,
“confidence”: 0.9856
},
{
“category”: “herederosTestamento”,
“confidence”: 0.0012
},
{
“category”: “cuentaBancaria”,
“confidence”: 0.001
},
{
“category”: “factura”,
“confidence”: 0.0009
},
{
“category”: “impuestoSucesiones”,
“confidence”: 0.0006
},
{
“category”: “ultimasVoluntades”,
“confidence”: 0.0004
},
{
“category”: “libroFamilia”,
“confidence”: 0.0003
},
{
“category”: “dni”,
“confidence”: 0.0001
}
],
“data”: [
{
“key”: “nes”,
“value”: [
“20220005890”
],
“confidence”: 0.9
},
{
“key”: “nis”,
“value”: ,
“confidence”: 0
},
{
“key”: “numPolicy”,
“value”: [
“1217397”
],
“confidence”: 0.9
}
]
}
]
}

THANKS!!

myJObject("result")(0)("data").Where(Function (x) x("key").Value(of String).equals("nes")).first()("value").toObject(Of String())

similiar you can also handle the others

myObject is the output from Deserialize JSON Activity

Hello @Alejandro_Vega_Romero

Can I get know the what are the data you need to extract.If it is less number of data then you can go for regex.

@Alejandro_Vega_Romero
also have a look on this generic approach returning a dictionary:

myJObject("result")(0)("data").ToDictionary(Function (x) x("key").Value(of String), Function (x) x("value").ToObject(Of String()))

Hey! Thx for the quick response!!

And should i put all that inside an Assign activity?

yes we can do it within an assign activity.

For prototyping as done in the screenshots we are using the immediate panel while debugging:
Understanding the 6 Debugging Panels of UiPath in the easiest way possible! - News / Tutorials - UiPath Community Forum

I know is too much to ask but, can you do it and show me some screenshots??

I’ve been with this for a while and i’m kinda overwhelmed… Dont’ worry if you can’t do it !!

grafik
grafik

Hi, the Assign is returning an empty string :thinking:

image

we dont think so. As mentioned above we would use the immediate panel for rnd and checking results.

When log message / write line is used for inspections an array is to handle by a string join like:
String.Join(",", arrValues).

When using arrValues.ToString we get back the datatype but not its values

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