cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Creating separate jsons

SL12345
New Contributor III

Hi Snaplogic experts,

i would like to ask you if there is chance to create from Json like this:

{
"CompanyName": "TestCompany",
"CompanyAddress": "TestAddress",
"CarDetails": [
 {"Brand": "BMW", "Year": "2020", "Fuel": "Petrol"},
 {"Brand": "Jaguar", "Year": "2020", "Fuel": "Diesel"},
 {"Brand": "GMC", "Year": "2019", "Fuel": "Petrol"}
]
}

three jsons like this:

{
  "CompanyName": "TestCompany",
  "CompanyAddress": "TestAddress",
  "Brand": "BMW",
  "Year": "2020",
  "Fuel": "Petrol"
}
,
{
  "CompanyName": "TestCompany",
  "CompanyAddress": "TestAddress",
  "Brand": "Jaguar",
  "Year": "2020",
  "Fuel": "Diesel"
}

it means โ€œCompanyNameโ€: โ€œTestCompanyโ€ and โ€œCompanyAddressโ€: โ€œTestAddressโ€ will be something like header for all jsons and Car details will be added to them. If yes, how to do it ? do i need separate route in order to get โ€˜headerโ€™ and second for Car details and then concat them somehow? do i need to use child pipeline as for each action? thank you

1 ACCEPTED SOLUTION

j_angelevski
Contributor III

Hi @SL12345,

Just use a JSON Splitter and split on $CarDetails array, but make sure you have enabled โ€œInclude scalar parentsโ€ option in the JSON Splitter.

image

Result:
image

View solution in original post

5 REPLIES 5

j_angelevski
Contributor III

Hi @SL12345,

Just use a JSON Splitter and split on $CarDetails array, but make sure you have enabled โ€œInclude scalar parentsโ€ option in the JSON Splitter.

image

Result:
image

SL12345
New Contributor III

thank you, that is really what i wanted ๐Ÿ™‚ and is it possible to wrap this content into object so from this:

{
  "CompanyName": "TestCompany",
  "CompanyAddress": "TestAddress",
  "Brand": "BMW",
  "Year": "2020",
  "Fuel": "Petrol"
}
,
{
  "CompanyName": "TestCompany",
  "CompanyAddress": "TestAddress",
  "Brand": "Jaguar",
  "Year": "2020",
  "Fuel": "Diesel"
}

create this? Adding โ€œCarsโ€ as header or envelope for body/content?

{
	"Cars":
{
  "CompanyName": "TestCompany",
  "CompanyAddress": "TestAddress",
  "Brand": "BMW",
  "Year": "2020",
  "Fuel": "Petrol"
}
,
{
  "CompanyName": "TestCompany",
  "CompanyAddress": "TestAddress",
  "Brand": "Jaguar",
  "Year": "2020",
  "Fuel": "Diesel"
}
}

Hi @SL12345 ,

Have you tried putting a groupByN snap behind it and as target field $Cars.
image

Regards

Jens

I need to correct my question โ€ฆ every JSON should have header โ€œCarsโ€

{
	"Cars":
{
  "CompanyName": "TestCompany",
  "CompanyAddress": "TestAddress",
  "Brand": "BMW",
  "Year": "2020",
  "Fuel": "Petrol"
}
,
{
  "Cars" :
{
  "CompanyName": "TestCompany",
  "CompanyAddress": "TestAddress",
  "Brand": "Jaguar",
  "Year": "2020",
  "Fuel": "Diesel"
}
}