erusev
1
Database resource return data like this:
{
"date": [
"2023-04-08",
"2023-04-09",
"2023-04-10"
],
"dl": [
"3",
"8",
"9"
],
}
How do I make them return data like this instead:
[
{"date": "2023-04-08", "dl": "3"},
{"date": "2023-04-09", "dl": "8"},
{"date": "2023-04-10", "dl": "9"},
]
You can run a transformer when the data is being returned from your api.
You can set this up in your database query here:
With javascript you can map the data to the new layout, eg:
const returnedData = {{ query.data }};
const newData= returnedData.date.map((date, index) =>
Object.assign({}, { date, dl: apiData.dl[index] })
);
return newData;
This is an example using static data, but in your case
1 Like
erusev
3
Thanks
I was hoping for something simpler, that I can easily use on multiple (or all) db resources, but it's nice that this is also an option.
erusev
5
@victoria This is exactly the type of thing I was hoping for
Thanks!