How can we convert a DataTable to JSON data in UİPATH?

We tend to use a lot of excel files as input when automating numerous business procedures.

We need to convert DataTable to JSON from time to time when conducting API automation.

To pass that as the body of a http request.

Converting DataTable to Json is especially useful for automating APIs.

Let’s get started on putting this task into practice.

The first step is to drag and drop. Build the DataTable Activity from the activities panel to the designer panel as shown below, as well as the input DataTable for this example:

image

We now have our datatable input, which is seen above.

Drag and drop an assign activity and enter the following LINQ expression:
image

dtExJson — This is a string variable that stores the datatable’s converted json data.
dtEx — This is the input datatable that was mentioned previously.
If you don’t see JsonConvert when typing there, you can import the namespace given below to acquire it:

After importing this, you’ll be able to see all of the JSON options available.

To observe the JSON output from the input DataTable, drag and drop a message box activity from the activities panel to the designer panel as shown below:

image

This is a basic method for converting DataTable data to JSON data for use in API automation.

2 Likes