09-16-2019 10:50 AM
Hi all, I have a table output with from a JSON generator that has its values in a separate row and column with the same Row Number. (see screenshot)
I’d like to combine those rows into one row with the same Row Number.
Any thoughts on how to go about doing this?
Solved! Go to Solution.
09-16-2019 01:45 PM
You are probably looking for the GroupByFields snap. That will allow you to group all of the input documents with the same Row number into a single output document. You can then use a Mapper to merge the resulting array of input documents together (if that’s what you’re after).
The expression to use in the Mapper would leverage the extend()
method on Objects to construct a new object from its arguments. In this case, we’ll be using the spread operator (i.e. three dots) to specify that the array of input documents should be passed as individual arguments to the extend()
method, like so:
{}.extend(...$group)
(Note: The {}
just makes an empty object that will be used as the base for the extension.)
Here’s a pipeline that does the above:
CombineRows_2019_09_16.slp (7.3 KB)
09-16-2019 11:38 AM
Hi,
You can use an aggregate Snap on all the fields, and in the group by section use Row number, and you will get the desired result
Images below for reference.
09-16-2019 12:00 PM
Thanks Anub, this will work for 4 fields, but what if I have 200+ and if I want to dynamically set the column headings.
I’ve attached the same sample pipeline, that generates the table as shown before.
JsonToMapperToTable_2019_09_16.slp (13.1 KB)
09-16-2019 01:45 PM
You are probably looking for the GroupByFields snap. That will allow you to group all of the input documents with the same Row number into a single output document. You can then use a Mapper to merge the resulting array of input documents together (if that’s what you’re after).
The expression to use in the Mapper would leverage the extend()
method on Objects to construct a new object from its arguments. In this case, we’ll be using the spread operator (i.e. three dots) to specify that the array of input documents should be passed as individual arguments to the extend()
method, like so:
{}.extend(...$group)
(Note: The {}
just makes an empty object that will be used as the base for the extension.)
Here’s a pipeline that does the above:
CombineRows_2019_09_16.slp (7.3 KB)
09-17-2019 05:52 AM
Thanks you @tstack ! That seems to do the trick!