Insert Json into another json

Friends, I would like to ask for your help in doing the following.

I have a “Set” node with which I generated a json that I need to insert into another json (in other node) I have tried to do it in many ways but I always get only the values ​​and not the full json.

This is the json I generated with a set node.

Here I need to insert the above json.

As always I really appreciate any help.

I am having a similar situation and being new I cannot make heads or tails of it. watching hope you find a solution!

Hi @patomi and @LBCAPI2,

The Item Lists node allows you to aggregate fields from separate items into individual items. My understanding is, however, that you are having a transformation in mind where entire items are transformed into a single array of JSON objects. This would be a nice feature idea for the Item Lists node, but for now, you can implement this custom transformation using the Function node.

This node can execute custom JavaScript snippets against all items and return the desired array. E.g. the below snippet would take the GoodsName and Quantity fields from each input item and write them as a new object in the GoodsList field of a single item:

// Create an empty array goodsList
let goodsList = [];

// Loop over inputs, extract data from GoodsName and Quantity fields, write them into a new object and push it to the goodsList array
for (item of items) {
  goodsList.push({
    GoodsName: item.json.GoodsName,
    Quantity: item.json.Quantity
  });
}

// Return an array containing a single item with a GoodsList field
return [{
  json: {
    GoodsList: goodsList
  }
}]

This results in a single item with a GoodsList field:

I hope this helps!

3 Likes

Friend, this was the perfect solution, thank you very much! I only had to make a few minor modifications to include the rest of the JSON, and it was perfect. Brilliant!

Very grateful for your help and for this amazing community. Thank You Very Much!

that’s how it was left with the final adjustments.

// Create an empty array goodsList
let goodsList = [];

// Loop over inputs, extract data from GoodsName and Quantity fields, write them into a new object and push it to the goodsList array
for (item of items) {
  goodsList.push({
    GoodsName: item.json.GoodsName,
    Quantity: item.json.Quantity
  });
}

// Return an array containing a single item with a GoodsList field
return [{
  json: {
	"Number": "LXXXXXX",
	"Date": "2021-10-05",
	"Type": 0,
	"Shipper": "BESTSTORE",
	"Depot": "Tienda",
	"Client": "Jhon Doe",
	"Address": "Lincon 3456, ny",
	"Note": "",
	"Phone": "+125325369874",
	"Email": "[email protected]",
GoodsList: goodsList,
		"CustomFields": 
		[
		{
			
		}
		]
}
}]
2 Likes