# Convert Json to Datatable without using loop

**URL:** <https://forum.uipath.com/t/convert-json-to-datatable-without-using-loop/349966>\
**Category:** Studio\
**Tags:** activities-panel, question, studio, system, webapi, activities\
**Created:** [October 1, 2021, 5:09pm UTC](https://forum.uipath.com/t/convert-json-to-datatable-without-using-loop/349966 "2021-10-01T17:09:10Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![joao\_adelio1](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/joao_adelio1/32/204853_2.png) [@joao\_adelio1](https://forum.uipath.com/u/joao_adelio1)\
**Post date:** [October 1, 2021, 5:09pm UTC](https://forum.uipath.com/t/convert-json-to-datatable-without-using-loop/349966/1 "2021-10-01T17:09:11Z")

</div>

Hello,

I’m deserialize a json for JOBJECT and would like to transform this JOBJECT straight to data table without looping due to high amount of information.

Below the structure of my JSON, the data table information would only be the highlighted ones.

> {  
> “name”: “relatorio”,  
> “elements”:[  
> {  
> **“cod\_ua”: “01”** ,  
> **“cod\_carteira”: “222”** ,  
> **“cpf\_cnpj”: “99999999999”** ,  
> },  
> {  
> **“cod\_ua”: “01”** ,  
> **“cod\_carteira”: “222”** ,  
> **“cpf\_cnpj”: “99999999999”** ,  
> }  
> ],  
> “links”:[  
> {  
> “rel”: “self”,  
> “href”:  
> “[https://teste.com](https://teste.com)”  
> }  
> ]  
> }

---

<div class="post-metadata">

**Author:** ![postwick](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/postwick/32/227083_2.png) [@postwick](https://forum.uipath.com/u/postwick)\
**Post date:** [October 1, 2021, 5:11pm UTC](https://forum.uipath.com/t/convert-json-to-datatable-without-using-loop/349966/2 "2021-10-01T17:11:26Z")

</div>

UiPath.WebAPI.Activities contains methods and activities for converting things to and from JSON.

> **[About the WebAPI Activities Package](https://docs.uipath.com/activities/docs/about-the-web-activities-pack)**
>
> This relatively small package enables users to perform SOAP or HTTP requests to any web APIs that support these protocols, including UiPath's Orchestrator API. The pack also contains activities that enable you to manipulate XML and JSON files, such...

---

<div class="post-metadata">

**Author:** ![rahulsharma](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/rahulsharma/32/55062_2.png) [@rahulsharma](https://forum.uipath.com/u/rahulsharma)\
**Post date:** [October 1, 2021, 5:13pm UTC](https://forum.uipath.com/t/convert-json-to-datatable-without-using-loop/349966/3 "2021-10-01T17:13:26Z")

</div>

you can simply parse it and convert to Datatable.

Below thread is quite helpful on this topic

> [@Convert json to Datatable](https://forum.uipath.com/t/convert-json-to-datatable/36639):
>
> { "Name": "Karan", "Adddress": "Kolkata", "Job\_Description": "Software Developer", "request": { "createdBy": "unknown", "comment": "Software", "Closure":[{ "type":"AB", "country":["India", "Pakistan"] }, { "type":"CD", "country":["India", "Pakistan"] } ] } } I want to convert this json to datatable. I am getting error when i…

---

<div class="post-metadata">

**Author:** ![sonaliaggarwal47](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/sonaliaggarwal47/32/234327_2.png) [@sonaliaggarwal47](https://forum.uipath.com/u/sonaliaggarwal47)\
**Post date:** [October 1, 2021, 5:14pm UTC](https://forum.uipath.com/t/convert-json-to-datatable-without-using-loop/349966/4 "2021-10-01T17:14:39Z")

</div>

Hi @joao_adelio1,

You can use below code to achieve the same.

This use build datatable activity and invoke code activity, its quite fast. No need to run thorugh loops as that would be time consuming.

[Sequence.xaml](https://forum.uipath.com/uploads/short-url/le9zEBysiJDjSMm5ZrCZklrIaKd.xaml) (10.0 KB)

Just make changes as required(few mentioned below for your quick reference:)

1. Change column names in build datatable activity to your column names.
2. Do regex changes (change per column names) in matches activity. Also mention your json onbject under Input in properties panel of matches activity.
3. Change the column names in invoke code activity.

And ta-da!!

You got your datatable 🙂

REgards  
Sonali

---

<div class="post-metadata">

**Author:** ![joao\_adelio1](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/joao_adelio1/32/204853_2.png) [@joao\_adelio1](https://forum.uipath.com/u/joao_adelio1)\
**Post date:** [October 6, 2021, 3:05pm UTC](https://forum.uipath.com/t/convert-json-to-datatable-without-using-loop/349966/5 "2021-10-06T15:05:51Z")

</div>

Thank you in advance for your help.

I tried to do as you told me, but my data table returns blank, I’ve attached the json and the code so you can see what I’m doing.

[TESTE.json](https://forum.uipath.com/uploads/short-url/btEXvHU9xUDHlLKkDED9b9deEZB.json) (2.5 KB)  
[Main.xaml](https://forum.uipath.com/uploads/short-url/tSWJiRkHDONVOYW3eFyHJ7lmHcI.xaml) (34.6 KB)

---

<div class="post-metadata">

**Author:** ![ppr](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/ppr/32/464097_2.png) [@ppr](https://forum.uipath.com/u/ppr)\
**Post date:** [October 6, 2021, 3:30pm UTC](https://forum.uipath.com/t/convert-json-to-datatable-without-using-loop/349966/6 "2021-10-06T15:30:03Z")

</div>

give a try on following

prepare a datatable with build datatable activity - dtData  
All cols similar to all properties from the JObject in elements  
parse the JSON string with Deserialize JSON activity - myJObject

Use an assign acitvity  
left: dtData  
right

```auto
(From x in myJObject("elements").Values(Of JObject)
let ra = x.Values.Cast(of Object).toarray
Select r=dtData.Rows.Add(ra)).CopyToDataTable

```

In case of you want to dynamize the datatable preparation you can loop over the first JObject properties or over an array with its names  
 ![grafik](https://global.discourse-cdn.com/uipath/original/3X/c/f/cfdf0ed78029943b3326ead01a6722e2968104e2.png)

Using this within a for each and combined with an add data column to dtData will reduce some manually effort

---

<div class="post-metadata">

**Author:** ![joao\_adelio1](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/joao_adelio1/32/204853_2.png) [@joao\_adelio1](https://forum.uipath.com/u/joao_adelio1)\
**Post date:** [October 7, 2021, 2:08pm UTC](https://forum.uipath.com/t/convert-json-to-datatable-without-using-loop/349966/7 "2021-10-07T14:08:25Z")

</div>

Thanks Peter,

can you help me on this other topic [Transform datatable string column into data time format (DD-MM-YYYY)](https://forum.uipath.com/t/transform-datatable-string-column-into-data-time-format-dd-mm-yyyy/351424)

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/system/32/182466_2.png) [@system](https://forum.uipath.com/u/system)\
**Post date:** [October 10, 2021, 2:09pm UTC](https://forum.uipath.com/t/convert-json-to-datatable-without-using-loop/349966/8 "2021-10-10T14:09:02Z")

</div>

Closed on October 10, 2021, 2:09pm UTC

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