Search code examples
anypoint-studiomulesoft

How to check if a field is null on payload from request body in Mulesoft?


I have 2 scenarios.

request body:

 {
    "id"="",
    "name"="Jane"
 }

Expected result:

"Success"

request body:

 {
    "id"="323",
    "name"="Jane"
 }

Expected result: "id field should be emptied."


Solution

  • this following dataweave will help you achieve what you are looking for

    %dw 1.0
    %output application/json
    ---
    {
        output: 'Success' when 
        payload.id == null or payload.id == "" 
        otherwise 'id field should be emptied.'
    }
    

    enter image description here

    enter image description here