jeanguy
February 12, 2021, 6:46pm
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
February 12, 2021, 8:36pm
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
February 12, 2021, 10:30pm
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
February 13, 2021, 9:04am
5
Thank you @jan
At the opposite, if I want to filter a data and filter every “myVariable: 123” ?
jan
February 13, 2021, 9:50am
6
Not sure I understand. Do you want to remove all items which do not have “myVariable” set to 123?
jeanguy
February 13, 2021, 5:26pm
7
I would like to remove all items “myVariable”.
jan
February 13, 2021, 6:00pm
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
February 15, 2021, 6:55am
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
February 15, 2021, 8:25am
10
Your output is not valid Javascript Object Notation
jeanguy
February 15, 2021, 1:52pm
11
Sorry I don’t understand why?
vuchl
February 17, 2021, 7:36am
12
Because the first thing represents an Array. The second is neither an Array nor an Object.
jeanguy
February 18, 2021, 11:08am
13
Ok, so to convert data with input like:
[
{
"order_detail": {
...some data
}
},
]
To output like:
{
"order_detail": {
...some data
}
},
jeanguy
February 26, 2021, 9:37am
15
Ok, so simple… thank you.