Rename Key - Objetc Array

Describe the problem/error/question

Hello, I have a json with an array inside it.
If I use Rename Key for a field that is not in the array, I can rename it.
If I try to use Rename Key for a field within an array of this Json, I can’t rename it.
This array may have several items, so I would have to rename them all.

What is the error message (if any)?

Please share your workflow

Example Json:
{ “CODPARC”: 0,
“CODBAIRRO”: 0,
“CODEND”: 1,
“CODCID”: 0,
“_orderitem_of_order”: [
{
“id”: 1,
“created_at”: 1690489203530,
“product_id”: 225596508,
“product_title”: “Cesta Oval Com Alça Em Papel Com Forro Em Tecido 27X20X12Cm”,
“sku_id”: 82801051,
“sku_title”: “Cesta Oval Com Alça Em Papel Com Forro Em Tecido 27X20X12Cm”,
“sku_partnerid”: “ROJE61516”,
“sku_ean”: “7895730615166”,
“order_id”: 1,
“idanymarket”: 127340785,
“amout”: 1,
“unit”: 21.9,
“gross”: 21.9,
“total”: 21.9
},
{
“id”: 2,
“created_at”: 1690489203530,
“product_id”: 225596321,
“product_title”: “Cesta Forro Em Tecido 27X20X12Cm”,
“sku_id”: 82801051,
“sku_title”: “Cesta Forro Em Tecido 27X20X12Cm”,
“sku_partnerid”: “ROJE61592”,
“sku_ean”: “7895730615189”,
“order_id”: 1,
“idanymarket”: 1273407802,
“amout”: 2,
“unit”: 22.9, //**** RENAME KEY TO: VLRUNIT
“gross”: 22.9,
“total”: 22.9
}
]
}
]

(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)

Share the output returned by the last node

Information on your n8n setup

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

Hi @BrunoNonato, welcome to the community!

I am sorry you’re having trouble.

Just to confirm, you want to rename keys inside your _orderitem_of_order array, right (in addition to renaming the array itself)? I’m afraid the “Rename Keys” node can’t quite handle this, but the Code node can help you here. Assuming you want to rename unit into VLRUNIT, the below workflow would do the job:

This is the result:

Hope this helps :slight_smile:

On a separate note, this would be an English language forum, so I’ve gone ahead and translated your post. It’d be great if you could post in English going forward so everyone else can follow the conversation. Thank you!

1 Like

Hi @MutedJam , sorry for the Portuguese, I didn’t pay attention.
But regarding the rename, it would be great if it worked inside the array.
On the other hand, the code solution you passed worked perfectly here.,

Thanks a lot for the help.

1 Like

Sweet, glad to hear this helps!

With regards to have “Rename Keys” work inside arrays I’ll also convert this question into a feature request, so you (and other users of course) can vote on having this implemented in the future.

Hello, @MutedJam
In fact, it would help to be able to rename the array already in this rename key, as it would reduce at least one node in the process.
Thanks for opening the improvement topic.

1 Like