jeanguy
12. Februar 2021 um 18:46
1
Hello,
I have a function node that return data:
then, I have an HTTP node wich get the three requests and return looks like:
[
{
"order_detail": {
"id": 106,
...some other data
}
},
{
"order_detail": {
"id": 107,
...some other data
}
},
{
"order_detail": {
"id": 108,
...some other data
}
}
]
I would like to add variable into each order_detail to have something like;
[
{
"order_detail": {
"id": 106,
"myVariable": 123,
...some other data
}
},
{
"order_detail": {
"id": 107,
"myVariable": 123,
...some other data
}
},
{
"order_detail": {
"id": 108,
"myVariable": 123,
...some other data
}
}
]
jan
12. Februar 2021 um 20:36
2
Just to be sure that I understand you correctly. The Function-Node and its data do actually not matter at all. All you want to do is to add an identical key to each of the order_detail objects that you get as result of the HTTP Request Node?
jan
12. Februar 2021 um 22:30
4
Then you can use a Function-Node with this code:
return items.map(item => {
item.json.order_detail.myVariable = 123;
return item;
});
Here the example workflow:
jeanguy
13. Februar 2021 um 09:04
5
Thank you @jan
At the opposite, if I want to filter a data and filter every “myVariable: 123” ?
jan
13. Februar 2021 um 09:50
6
Not sure I understand. Do you want to remove all items which do not have “myVariable” set to 123?
jeanguy
13. Februar 2021 um 17:26
7
I would like to remove all items “myVariable”.
jan
13. Februar 2021 um 18:00
8
I assume you mean with ‘item’ → 'property`. In this case the function would look like this:
return items.map(item => {
delete item.json.order_detail.myVariable;
return item;
});
Here the example workflow:
jeanguy
15. Februar 2021 um 06:55
9
thanks a lot.
One last thing (I hope…), how unserialize the data? So start with:
[
{
"order_detail": {
...some data
}
},
{
"order_detail": {
...some data
}
},
{
"order_detail": {
...some data
}
}
]
and ave this return:
{
"order_detail": {
...some data
}
},
{
"order_detail": {
...some data
}
},
{
"order_detail": {
...some data
}
}
vuchl
15. Februar 2021 um 08:25
10
Your output is not valid Javascript Object Notation
jeanguy
15. Februar 2021 um 13:52
11
Sorry I don’t understand why?
vuchl
17. Februar 2021 um 07:36
12
Because the first thing represents an Array. The second is neither an Array nor an Object.
jeanguy
18. Februar 2021 um 11:08
13
Ok, so to convert data with input like:
[
{
"order_detail": {
...some data
}
},
]
To output like:
{
"order_detail": {
...some data
}
},
jeanguy
26. Februar 2021 um 09:37
15
Ok, so simple… thank you.