From one nested JSON to another nested JSON: how to parse the nested array

I poll customer orders from a web service that looks like this:


[
  {
     "Data": "2022-11-10T00:00:00",
     "Total_spent": 445,
     "IDCliente":962961,
     "Endereco":"RUA REJANE FREIRE CORREIA",
     "NumeroEnd":253,
     "Cidade":"JOAO PESSOA",
     "Fone1":"(81) 8767-8419",
     "Email":"[email protected]",
     "Itens":[
       {
         "IDItem":77259,
         "Quantidade":1,
         "Preco":55,
         "Nome":"SOLAR TRADICIONAL"
       },
       {
         "IDItem":78909,
         "Quantidade":1,
         "Preco":49,
         "Nome":"SOLAR ESPECIAL"
       }

I need to create another JSON that has the same structure but with diferent names for each variable. For exemplo “Data” will be sent as “sale_date”.

I started using SET node, but I am unsure how to transform de nested part for products (“Itens”):

I don’t know any JS, can someone help?

Information on your n8n setup

  • n8n version: 0.198.2
  • Database you’re using (default:): SQLite
  • Running n8n with the execution process [own(default), main]:
  • Running n8n via [Docker, npm, n8n.cloud, desktop app]: desktop app

I now tried to add an array as aditional value in Set, but is treating the variables as values and not variables

Hi @fxholl

you can use the item lists node to retrieve those nested items.

ok, but how do I insert them again in the final Json?

Right now I have this workflow:

Here is the output from Set node:

You can keep the other fields.
It all depends on what your output needs to be.

@BramKn the output needs to be an array with the same product information, with different labels.

For instance, if in the input Json it says
Quantidade : 3
the output Json needs to become:
quantity”: 3

I tried to map the variables in an expression, but it is not working:

So you want the same format just other field names within the array?
Then I think you have 2 options.

  1. use a function node to go through all the array items and change the names.
  2. split the array rename the fields and then aggregate the items back into the array. might need a split in batches=1 for that to make it easy to work with.

@BramKn that’s correct. Is either option possible for someone without JS coding experience or skill?

the second would be just using n8n nodes.