Struggling again with Set

Hi all,

I’m again trying to transform some datas extracted from an API with set, but it seems I need a function to do so, but I don’t know how to do.

Here is a mockup workflow with some datas, and I expect a table with time and power as column values.

Is there a way to do it without code ? If not, what would be the right function ?

Thanks a lot for your help !

Hey @mcc37,

You will need to write a function to transform the data. In the sample data you provided, are the Key values the time? Eg. for 26400: 0, is 26400 the time and 0 the power?

Yes, 26400 is time and 0 power.

It’s a list of power value every 5 minutes between a start date and a end date.

I wonder if the new Item List helper node that @maxT has been working on would help.

Hey @mcc37,

Using the mock data you provided, I’ve written this function that might be helpful.

const data = Object.keys(items[0].json.propertyName).map(i => ({json:{time:i, power:items[0].json.propertyName[i]}}));
return data;
2 Likes

Thanks a lot @harshil1712 , it works perfectly !

Not so easy to wrote those functions, would you have a recommandations of web pointers to learn basics of javascript / json so I would be able to build it ?

@mcc37 as much as some people don’t like them the W3Schools javascript page is great for reference, Mozilla have a great reference page with some tutorials as well.

Another handy reference is here on the community pages, The search box at the top is great for looking at older questions and might help with some functions as chances are someone has wanted to do the same thing before.

4 Likes

Thanks for mentioning me @Jon - just checked the usecase and the V1 of Item List helper node would not be able to perform this specific mapping. Will ensure this usecase is recorded when we look to add functionality to the node!

2 Likes

Thanks Jon for those links !

Thanks @maxT. This node seems to be very interesting, I regularly have this type of use case and each API has its own way of sharing series of datas.

That’s good to know. If you could, it would be super helpful if you could DM me a few examples cases. Best format would be simply an “input json” and an expected “output json”. Then we can use these cases directly when designing new operations for the node. Thanks :pray: