Length Validation in Dataweave

Rohan Shinde picture Rohan Shinde · Oct 16, 2015 · Viewed 9.8k times · Source

How to do length validation in Mule Dataweave

%dw 1.0
%output application/xml
---
(payload default []) map {
    Field1:$.Field11,
    Field2:$.Field22,
    Field3:$.Field33,
    Field4:$.Field44
}

I want to do validation like max Length of Field22 < 20

How to achieve this in Mule Dataweave

Answer

Ryan Carter picture Ryan Carter · Oct 16, 2015

You can use a when condition on an invidual field using the sizeOf operator:

%dw 1.0
%output application/xml
---
(payload default []) map {
    Field1:$.Field11,
    (Field2: $.Field22) when (sizeOf $.Field22) < 20,
      Field3:$.Field33,
    Field4:$.Field44
}