Extracting value from JSON file

Hi everyone.
I have a problem when searching for an attribute of a json variable.
In my project, I need to use a WS that returns a json file with several attributes.
After that I need to insert the information of this json file into the database and that’s where the problem lies.

There is a json attribute that is not present in every file so when I try to do varJson.Item("x-cod") it gives an error in the project, but only when the "x-cod" attribute does not exist in the file.

Is there any way to validate if the error and if it doesn’t exist returns 0, null or something else?

Hi @tainan.ramos,

A very rudamentary way is to read the json file as text file by using the Read Text File activity. This returns a string. Then you can determine if that text string has “x-cod” by using

If condition = TextStringReadFromFile.contains("x-cod")

If true, Then extract value.
Before extracting the value in the Then block you can use DeserializeJson activity to extract value of Json using
Some helper code for json parsing / value extraction in UiPath : Iterating through Jobject - #6 by jeevith

Else do nothing - skip the parsing / extraction.

Hope this gives you some ideas.

2 Likes

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