02-18-2021 08:58 AM
I have a REST API that returns something like the following:
entity":
{
“items”:
[
{
“tableName”:
“mytable”
“count”:
7995
“columnNames”:
[
“c1”,“c2”,“c3”,“c4”
]
“rows”:
[
[r1c1value,r1c2value,r1c3value,r1c4value],[r2c1value,r2c2value,r2c3value,r2c4value],[…],[…],[…],[…],[…],[…],[…],[…]
]
}
]
}
When I refer to jsonPath($, “entity.items[*]”) it gives me columns as an array of columns and the rows are an array of rows.
How can I parse this so that I can map it to a Mapper to put into SQL?
Thanks
Solved! Go to Solution.
02-18-2021 03:25 PM
If I captured your input data correctly, this attached pipeline should help get you started:
Community.9525.slp (4.8 KB)
The mapper combines the Array map() method with the sl.zipObject() method to bring the column names and row values together in an object array. The following splitter will flatten the data for your SQL Insert.
02-19-2021 12:02 PM
I got it.
I had to do the splitter first and get [rows] and [columns]
then I was able to modify the sl.ZipObject slightly from your original to:
jsonPath($, “rows[]").map(x=>sl.zipObject(jsonPath($, "columnNames[]”),x))
It was like it couldn’t reference it from the entity level.
02-26-2021 01:00 PM
Ok well… Here’s another issue.
That export works great as long as the field names are unique in the output of the JSON.
But if they are the same it fails and there is no way I can think of to remedy that issue.
so this is really weird but in the API we are calling from it returns subtables inside the output of the parent table example.
select ,child. from parent
I wouldn’t mind if I was able to get the columns ordinally or have it append some kind of index to the field. say id,id_1,id_2.
Put I haven’t been able to figure that out.
02-28-2021 02:20 PM
Please find the attached sample pipeline containing the expression that you can use to append an index to the object keys.
SL_Community_1_2021_02_28.slp (4.7 KB)
Hope that will helps!
Regards!