cancel
Showing results for 
Search instead for 
Did you mean: 

Create hierarchical Json from mapper output

SL12345
New Contributor III

Hello Snaplogic experts,

is it possible from input

[
{
"Manufacturer":
"BMW"
"type":
"M3"
"Fuel":
"petrol"
}
{
"Manufacturer":
"BMW"
"type":
"M5"
"Fuel":
"petrol"
}
{
"Manufacturer":
"Mercedel"
"type":
"GLS"
"Fuel":
"diesel"
}
]


create output like this: 
[
        {
"Manufacturer": BMW
   "Infos":
        [
        {
        "type":"M3"
        "Fuel":"petrol"
        }
        {
        "type":"M5"
        "Fuel":"petrol"
        }
        ]
        }
        {
"Manufacturer": Mercedes
   "Infos":
        [
        {
        "type":"GLS"
        "Fuel":"diesel"
        }     
        ]
        }
]

ive tried with group by fields and withou success … iam curious if it is possible to add “Infos” into output, if it wasnt mentioned in input

thank you

1 ACCEPTED SOLUTION

Aleksandar_A
Contributor III

Hello,

You can achieve this by using a Mapper Snap with the following settings:

image

Try it, and let me know if this helps.

BR,
Aleksandar.

View solution in original post

7 REPLIES 7

SL12345
New Contributor III

Hi, it looks like this:

[
        {
"Manufacturer": BMW
   "Infos":
        [
        {
        "type":"M3"
        "Fuel":"petrol"
        }
        ]
 "Manufacturer": BMW
   "Infos":
        [       
        {
        "type":"M5"
        "Fuel":"petrol"
        }
        ]
        }
        {
"Manufacturer": Mercedes
   "Infos":
        [
        {
        "type":"GLS"
        "Fuel":"diesel"
        }     
        ]
        }
]

i would like to group it/sort it under one Manufacturer

You can try as I have in the pipeline attached below.

First I’m grouping by the Manufacturer field, and then I’m concatenating the Infos arrays in one array.

–sl-comm-hierarchial-json_2023_06_14.slp (8.1 KB)

Regards,
Aleksandar.

SL12345
New Contributor III

Thank you very much Aleksandar …thats what i was looking for