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 فبراير 2021، 8: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 فبراير 2021، 10: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:
Thank you @jan
At the opposite, if I want to filter a data and filter every “myVariable: 123” ?
jan
13 فبراير 2021، 9:50ص
6
Not sure I understand. Do you want to remove all items which do not have “myVariable” set to 123?
I would like to remove all items “myVariable”.
jan
13 فبراير 2021، 6: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:
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 فبراير 2021، 8:25ص
10
Your output is not valid Javascript Object Notation
Sorry I don’t understand why?
vuchl
17 فبراير 2021، 7:36ص
12
Because the first thing represents an Array. The second is neither an Array nor an Object.
Ok, so to convert data with input like:
[
{
"order_detail": {
...some data
}
},
]
To output like:
{
"order_detail": {
...some data
}
},
Ok, so simple… thank you.