0

How can i apply the filter to remove empty array while doing transformation. I tried to apply sizeOf ($) != 0 but that is not working. I am able to do this by creating function but here i have to remove while doing map.kindly suggest solution for that.

            %dw 1.0
            %output application/json
            ---
            {
            employees: {
                employee:  (flowVars.varInputData.request.application.applicants) map ((applicant , indexOfApplicant) -> {
                        (flowVars.varMbResponse.application.applicants filter ($.customerID == applicant.customerID) map {
                        "source": "EMI_IMP",
                        "loanData": ($.customBureauResponse.customResponse.accountList map {
                                    "customerGender": applicant.gender
                })
                })

                })  
            }
            }

Response from the dwl:

            {
            "EMIComputations": {
                "eMIComputation": [{
                        "source": "EMI_IMP",
                        "loanData": [{
                                "customerGender": "F",
                            },
                            {
                                "customerGender": "M",
                            }
                        ]
                    },
                    {

                    },
                    {

                    }
                ]
            }
            }

expected output:

            "EMIComputations": {
                "eMIComputation": [{
                        "source": "EMI_IMP",
                        "loanData": [{
                                "customerGender": "M",
                            },
                            {
                                "customerGender": "M",
                            }
                        ]
                    }
                ]
            }
            }
4
  • Try changing your expression to (sizeOf $) != 0 and try again. Commented Jun 6, 2020 at 13:15
  • 1
    Does this answer your question? How to remove empty array objects from dataweave response Commented Jun 6, 2020 at 14:19
  • @aled by using function i am also able to do but i have to remove in one transformation when i am doing map Commented Jun 7, 2020 at 5:37
  • 1
    Just apply the function where you needed. For example to map the payload without the empty values: (filterEmpty(payload)) map .... There is not way to automate it, if that is what you are asking for. Commented Jun 7, 2020 at 12:48

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.