cancel
Showing results for 
Search instead for 
Did you mean: 

Filter attributes out of object

Max
New Contributor II

Hello,

I need to filter a payload based on user entered parameters. The user can use the fieldsNames parameter to provide a list of fields they want returned, instead of all 30 attributes in the payload. In the examples below I need to filter the payload down to the list of fields specified in the fieldNames parameter. If an attribute in the gsn section is part of the fieldNames parameter then the gsn tag must be included else it can be left out. Any help is very much appreciated. Thank you.

Example1:

parameter: fieldNames = "rpn,gpn,artcode,gtin,grossWeight"

"products": [
{
"gcpn": "82700123",
"rpn": "009600-123",
"productName": "someProduct",
"gpn": "G12345",
"productLineCode": "009XXX",
"artCode": "0019-10",
"gsn": [
{
"gtin": "10827123",
"parentGtin": "0082700123",
"grossWeight": ".005 gr",
"netWeight": ".005 gr",
"depth": ".005 cm",
"width": ".005 cm"
}
]
}
]
 
Final OutPut should be:
"products": [
{
"rpn": "009600-123",
"gpn": "G12345",
"artCode": "0019-10",
"gsn": [
{
"gtin": "10827123",
"grossWeight": ".005 gr"
}
]
}
]
 

Example2:

parameter: fieldNames = "rpn,gpn,artcode"

"products": [
{
"gcpn": "82700123",
"rpn": "009600-123",
"productName": "someProduct",
"gpn": "G12345",
"productLineCode": "009XXX",
"artCode": "0019-10",
"gsn": [
{
"gtin": "10827123",
"parentGtin": "0082700123",
"grossWeight": ".005 gr",
"netWeight": ".005 gr",
"depth": ".005 cm",
"width": ".005 cm"
}
]
}
]
 
Final OutPut should be:
"products": [
{
"rpn": "009600-123",
"gpn": "G12345",
"artCode": "0019-10"
}
]
1 ACCEPTED SOLUTION

koryknick
Employee
Employee

@Max - with the solution provided, you can get the desired output you show above.

Only gsn:

koryknick_0-1702993531737.png

koryknick_1-1702993565808.png

Then without gsn:

koryknick_3-1702993680652.png

koryknick_4-1702993712954.png

 

By the way, if you are calling this from a triggered task to specify the fields you want, make sure you clear any default values from your task definition.

Hope this helps!

View solution in original post

5 REPLIES 5

koryknick
Employee
Employee

@Max - with the solution provided, you can get the desired output you show above.

Only gsn:

koryknick_0-1702993531737.png

koryknick_1-1702993565808.png

Then without gsn:

koryknick_3-1702993680652.png

koryknick_4-1702993712954.png

 

By the way, if you are calling this from a triggered task to specify the fields you want, make sure you clear any default values from your task definition.

Hope this helps!