Contact Us 1-800-596-4880

sizeOf

DataWeave 2.1 is compatible with Mule 4.1. Standard Support for Mule 4.1 ended on November 2, 2020, and this version of Mule will reach its End of Life on November 2, 2022, when Extended Support ends.

Deployments of new applications to CloudHub that use this version of Mule are no longer allowed. Only in-place updates to applications are permitted.

MuleSoft recommends that you upgrade to the latest version of Mule 4 that is in Standard Support so that your applications run with the latest fixes and security enhancements.

sizeOf(Array<Any>): Number

Returns the number of elements in an array.

Returns 0 if the array is empty.

Example

This example returns a count of elements in the input array.

Source

%dw 2.0
output application/json
---
{
  "arraySize": sizeOf([1,2,3])
}

Output

{
  "arraySize": 3
}

sizeOf(Object): Number

Returns the number of key-value pairs in an input object.

Returns 0 if the object is empty.

Example

This example counts the key-value pairs in an input object.

Source

%dw 2.0
output application/json
---
{
  objectSize: sizeOf({a:1,b:2})
}

Output

{
  "objectSize": 2
}

sizeOf(Binary): Number

Returns the byte length of a binary.

Example

This example returns the size of a binary value that is passed through a variable. The binary is returned by a function in core::Binaries.

Source

%dw 2.0
import * from dw::core::Binaries
var var1 = fromBase64(000000)
output application/json
---

{ "size" : sizeOf(var1) }

Output

{
  "size": 4
}

sizeOf(String): Number

Returns the number of characters (including white space) in an string.

Returns 0 if the string is empty.

Example

This example returns the number of characters in the input strings.

Source

%dw 2.0
output application/json
---
{
  "sizeOfString1" : sizeOf("MuleSoft"),
  "sizeOfSting2" : sizeOf("my string")
}

Output

{
  "sizeOfString1": 8,
  "sizeOfSting2": 9
}