Compare `filter` macro vs `FOR` expression filtering
masterJSLT allows filtering via a filter macro or directly within a FOR expression. While the filter macro is functional, the FOR expression syntax is generally preferred for readability when performing transformations and filtering in a single pass.
Using the filter macro:
[for (filter(.path.to.array, .condition)) .output.path]
Using FOR expression filtering:
[for (.path.to.array) .output.path if (.condition)]
// Using filter macro
[for (filter(.Reservations.Instances, .EbsOptimized)) .InstanceId]
// Using FOR expression (preferred)
[for (.Reservations.Instances) .InstanceId if (.EbsOptimized)]