Converting Simple JSON String To Data Table Using C# In UiPath

API (Application Programming Interface) is a set of commands supported by a particular application that enables two or more software systems to communicate and exchange data. API Automation enables multiple application integration like fetching data from one, filtering and processing from another, and then passing it to the end application.
For example, UiPath provides API Integration with Servicenow that allows you to automate multiple features of Servicenow using API like inserting, updating, deleting records. One more example can be fetching employee data from Microsoft Azure using API.
Now in most cases, the output of data from API is in JSON format. Therefore, in this article, we are going to see a step by step process on how to convert a simple
JSON output/string to a Data Table using C# in UiPath.
Step 1 - Select Process under New Project in UiPath
Step 2 - Fill in the details and give an informative description
Now at this step, you need to make sure that in the language option you select C# since we are doing the conversion using the same.
Step 3 - Creating variables
We will create the following two variables in the variable panel,
  • JSONString
    It will be used to store the JSON string for processing.

  • DT
    It will store the converted data table.
The pictures depict the variables created,
Step 4 - Assigning a value to JSON string
In this step we will use an assign activity to assign JSON value to the JSON string variable,
Step 5 - Logic to convert Simple JSON to Data Table
We are using an assign activity to assign the converted JSON String to a Data Table. The logic in the assigned activity is as follow,
DT = (DataTable)JsonConvert.DeserializeObject(JSONString, (typeof(DataTable)));
First, we deserialize the JSON to an object of the type data table and then convert it to a Data Table using the JsonConvert function.
Step 6 - Checking the output data table
To verify that we have successfully converted the JSON String to Data Table we use a message box to display the total number in a data table in the following way,
Step 7 - Output in the message box
As we can see in the below message box picture the total number of rows is 6 which matches with the input JSON String.
Now, this data table can be used for further processing for inputting in applications, websites, portals, etc...
Hurray! With 7 simple and quick steps we have successfully converted JSON String to Data Table using C# in UiPath. You can find the Source Code Zip file attached.
Thank you for reading the complete article. Do comment your suggestions or the topics you would want me to write articles about.