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 pay...
Max - with the solution provided, you can get the desired output you show above.
Only gsn:
Then without gsn:
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.
Max - please download and decompress the attached zip file, then import the SLP file as a new pipeline. It is an example of how I recommend approaching this use case. Note that I opted to break out the gsn fields from the base-level products fields because handling those field lists in a single set requires object tree traversal which is not a simple task.
The pipeline as exported is showing your second use case where "gsn" fields are ignored. You can add "gsn" to the productFields pipeline parameter and "gtin,grossWeight" to the gsnFields pipeline parameter to see your first use case.
The JSON Generator is just your sample data.
The first Mapper (Remap gsn) is using the Mapping Root so I can work within the objects of that sub-element.
The expression is using the Object.filter() method to select only the fields listed in the "gsnFields" pipeline parameter. Within that callback function, I'm using the String.split() method to get an array containing the field names, then I'm using the Array.indexOf() method to see if the current field of the object is in that list.
The next Mapper (Remap Products) is doing very similar logic on the products array to filter down to the desired set of fields.