How to Convert Datatable into Json object

Hi

Is any Activity in UIPath which will convert Datatable into Json object ? Do you have any reference or example which shows datatable conversion into Json objects.

Thanks,
Ranjan

2 Likes

Did you try JsonConvert.SerializeObject(DataTable)

6 Likes

This should work.

Do note that DataTable and JSON serialization have corner cases that don’t play nice with each other (deseriaized schema is completely based on first row).

1 Like

I couldnt get this to work. Could anyone assist with examples on how to convert a DATA TABLE to JSON? Or even CSV to JSON in UIPATH?

Thank!

There is a bug when first trying to use the JsonConvert.SerializeObject. The function reads as an error until you create a variable of type JsonConvert. You can delete the variable afterward.

4 Likes

@vvaidya Can you please help me how to convert word file into Json.

I am very new to UIPATH please help me.

thanks

Hi @Ranjan,

Here you go below Are some Operation being Performed:-

  1. Convert Text File To into Formatted Excel Data Column
  2. Read the the Formatted DataTable and Convert to JSON

Attached the Sample Script:-

JSON_TO_DataTable.zip (26.4 KB)

Note:Require To Import NameSpaces

1.Microsoft.Office.Interop.Excel
2.Microsoft.Office.Tools.Excel

Below are The Sample ScreenShots:-

1.Raw Data

2. FormattedExcel

3.Final JSON Result

Regards
Sanjay Shankhla

1 Like

Hello Ranjan,
In this video I do a lot of stuff with JSON (Chapter included) :

15:55 Datatable to JSON
17:50 JSON to Datatable

Thanks,
Cristian Negulescu

Hi Mate,

I saw your suggestion for datatable to json string convert.

I have json format like this, how can ı turn it with Invoke Code with your method.

I tried json.searilize method but the result like this ;

[{“task_id”:509.0,“tesvik_isim”:“55ON”,“status”:“Teşvikten Yararlanabilirsiniz”,“tesvik_tutari”:“178,88 TL”,“aciklama”:“Kazanç :3.577,50 TL”}

I need it like this ;

[{“task_id”:“509”,“tesvik_isim”:“55ON”,“status”:“Teşvikten Yararlanabilirsiniz”,“tesvik_tutari”:“178,88 TL”,“aciklama”:“Kazanç :3.577,50 TL”}

Need to change 509.0 to “509” how can ı do that ?

Could you please help me about it?