How to create datatable from Json object?

Hi Guys,

Requirement is as below:
We are reading text from json file and then deserializing into json object.

Now we don’t want to save data from json object as dictionary but as datatable.

How can this be achieved?

Regards
Sonali

https://www.google.com/search?q=uipath+convert+json+to+datatable+site:forum.uipath.com&safe=active&rlz=1C1GCEA_enUS956US956&sa=X&ved=2ahUKEwiNm7m-35XzAhXZSzABHU53DcAQrQIoBHoECAoQBQ&biw=1920&bih=937&dpr=1

Hi @sonaliaggarwal47 … For your reference…

1 Like

Hi @Yoichi,

I referred your solution in below post:

My json text is as below:
{
“SitLib”: [
{
“Sites”: “https://site1”,
“Libraries”: “BG,HRM”
},
{
“Sites”: “https://csite2”,
“Libraries”: “SD”
}
]
}

And I have modified the invoke code you shared like below:
System.Data.DataRow row;
foreach (System.Text.RegularExpressions.Match m in matches){
row=dt.NewRow();
row[“Sites”]=m.Groups[1].Value;
row[“Libraries”]=m.Groups[2].Value;
dt.Rows.Add(row);
}

And match regex as below:
“Sites”"\s*:\s*""([^""]+)"",\s+"“Libraries”"\s*:\s*""([^""]+)"""

But looks like I am missing something here, getting below error:
RemoteException wrapping System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. —> RemoteException wrapping System.ArgumentException: Column ‘Sites’ does not belong to table TableName.
at System.Data.DataRow.GetDataColumn(String columnName)

Could you please help identify the issue?

Regards
Sonali

Hi,

This means there is no column named ‘Sites’ in the datatable. Can you check if it’s made correctly before then.

Regards,

1 Like

Hello Sonali,
IN this video at minute 17:50 I show how I create datatable from JSON:

Thanks,
Cristian

1 Like

Hi @Yoichi,

I got what was the issue, its resolved.

Thank you :slight_smile:

Regards
Sonali

Thank you everyone for your help :slight_smile:

Regards
Sonali

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