joao_adelio1
(Joao Paulo da Silva Adelio)
October 1, 2021, 5:09pm
1
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 ”
}
]
}
1 Like
postwick
(Paul Ostwick)
October 1, 2021, 5:11pm
2
UiPath.WebAPI.Activities contains methods and activities for converting things to and from JSON.
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...
you can simply parse it and convert to Datatable.
Below thread is quite helpful on this topic
{
"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…
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 (10.0 KB)
Just make changes as required(few mentioned below for your quick reference:)
Change column names in build datatable activity to your column names.
Do regex changes (change per column names) in matches activity. Also mention your json onbject under Input in properties panel of matches activity.
Change the column names in invoke code activity.
And ta-da!!
You got your datatable
REgards
Sonali
joao_adelio1
(Joao Paulo da Silva Adelio)
October 6, 2021, 3:05pm
5
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 (2.5 KB)
Main.xaml (34.6 KB)
ppr
(Peter Preuss)
October 6, 2021, 3:30pm
6
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
(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
Using this within a for each and combined with an add data column to dtData will reduce some manually effort
2 Likes
joao_adelio1
(Joao Paulo da Silva Adelio)
October 7, 2021, 2:08pm
7
system
(system)
Closed
October 10, 2021, 2:09pm
8
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.