Help with DB query output

Hello,

I need to create DB query output in a proper format for a 3rd party system which will query my Wappler APIs.

My current DB general query output is this:

My target is to make output looks like this:

output: [{sam_sip_group_number:“222”,numbers:[2548783, 587855, 554587],{sam_sip_group_number:“333”,numbers:[121212, 131313]]

Output should contain 2 arrays: one with all sam_sip_group_number, and inside this array with all number under this group named “numbers”.

I’ve already tried to play around with repeats and group by collection options - but I just can’t catch this logic.

Would be much appreciate if you could lead me with right way of achieving this.
Thank you in advance.

First you need to group your results by the sam_sip_group_number and then get the results for each of these values in an array.

So add a repeat step, after your query and apply the group by formatter to it:

Then add a set value step inside the repeat, add a name sam_sip_group_number for it and select $name as a value:

And finally, create another set value step, add a name of numbers to it and first join by sam_sip_group_sip_number then split this string to an array:

May I ask you to paste code that’s inside Set Value numbers which is in last step in last screenshot?

Sure:

{{$value.join(',', 'sam_sip_group_sip_number').split(',')}}

You first join the values of the sam_sip_group_sip_number for each of the sam_sip_group_number and then you split the results to an array.

Thank you very much, @Teodor
Works just like I needed.

1 Like