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

AleksandarAngel
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

AleksandarAngel
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.

Yes sir, it works as i wish โ€ฆ ๐Ÿ™‚

My output looks like this: every โ€œInfosโ€ has its own manufacturer object. Is it possible to group/map it somehow

so there will be one Manufacturer field for x objects? in this case only one manufacturer for X3 and X5 type

[
        {
"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 into/with Manufacturer  so i will have only one Manufacturer for x types

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

do i need group by field or structure snap ?

thank you

Hi, can you please provide me the exact valid JSON?