fxholl
November 13, 2022, 11:55am
1
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
fxholl
November 14, 2022, 2:05pm
2
I now tried to add an array as aditional value in Set, but is treating the variables as values and not variables
BramKn
November 14, 2022, 2:11pm
3
Hi @fxholl
you can use the item lists node to retrieve those nested items.
fxholl
November 14, 2022, 2:37pm
4
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:
BramKn
November 14, 2022, 2:39pm
5
You can keep the other fields.
It all depends on what your output needs to be.
fxholl
November 15, 2022, 9:17pm
6
@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:
BramKn
November 16, 2022, 8:05am
7
So you want the same format just other field names within the array?
Then I think you have 2 options.
use a function node to go through all the array items and change the names.
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.
fxholl
November 16, 2022, 8:40am
8
@BramKn that’s correct. Is either option possible for someone without JS coding experience or skill?
BramKn
November 16, 2022, 8:40am
9
the second would be just using n8n nodes.