How to Convert DataTable to JSON data in UiPath
While automating many business processes we tend to use a lot of excel files as input.
Sometimes while performing API automation we need to convert DataTable to JSON.
In order to pass that as a body to http request.
Converting DataTable to Json mostly helps while performing API automation.
Let’s jump into the practical implementation of this task.
Step1: Drag and Drop Build DataTable Activity from activities panel to designer panel as shown below and also the input DataTable that we are going to use in this example:
Now we have our datatable input that is shown above.
Step2: Drag and Drop an assign activity and provide the LINQ expression as shown below:
- DTtoJson – It is a variable of type string that will store the converted json data from datatable.
- DT – It is the input datatable that is used earlier.
If you are not able to see JsonConvert when you are typing there then you can import the namespace to get that which is shown below:
After importing this you can able to find all the JSON options that can be used here.
Step3: Drag and Drop a message box activity from activities panel to designer panel as shown below to see the JSON output from the input DataTable:
The above input DataTable is now converted to JSON data as we can see that in the above image.
This is a simple way of converting DataTable to JSON data in order to use this as input in API automation.