---
schema_version: "1"
id: 7ee0159139bbb8144f8d0c6326d23565b99108dbddba799493abf6780a1cea63
title: Coercions (dw::util::Coercions)
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/dataweave/2.11/dw-coercions.md
canonical_url: https://docs.mulesoft.com/dataweave/2.11/dw-coercions
source_site: docs.mulesoft.com
content_type: documentation
content_hash: a50c942e1d4662657f5f412d12fc57de8fdbb7bd40645323ffe84652ffe22c49
description: MuleSoft Documentation Site
release: "2.11"
latest: false
---
---
product: DataWeave
version: 2.11
---

# Coercions (dw::util::Coercions)

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

This utility module assists with type coercions.

To use this module, you must import it to your DataWeave code, for example, by adding the line
`import * from dw::util::Coercions` to the header of your DataWeave script.

_Introduced in DataWeave version 2.4.0._

## Functions

<table><colgroup><col> <col></colgroup><thead><tr><th>Name</th><th>Description</th></tr></thead><tbody><tr><td><p><a href="https://docs.mulesoft.com/dataweave/2.11/dw-coercions-functions-toarray">toArray</a></p></td><td><p>Splits a <code>String</code> value into an <code>Array</code> of characters.</p></td></tr><tr><td><p><a href="https://docs.mulesoft.com/dataweave/2.11/dw-coercions-functions-tobinary">toBinary</a></p></td><td><p>Transform a <code>String</code> value into a <code>Binary</code> value using the specified encoding.</p></td></tr><tr><td><p><a href="https://docs.mulesoft.com/dataweave/2.11/dw-coercions-functions-toboolean">toBoolean</a></p></td><td><p>Transform a <code>String</code> value into a <code>Boolean</code> value.</p></td></tr><tr><td><p><a href="https://docs.mulesoft.com/dataweave/2.11/dw-coercions-functions-todate">toDate</a></p></td><td><p>Transforms a <code>String</code> value into a <code>Date</code> value using the first <code>Formatter</code> that matches with the given value to transform.</p></td></tr><tr><td><p><a href="https://docs.mulesoft.com/dataweave/2.11/dw-coercions-functions-todateornull">toDateOrNull</a></p></td><td><p>Transforms a <code>String</code> value into a <code>Date</code> value using the first <code>Formatter</code> that matches with the given value to transform.</p></td></tr><tr><td><p><a href="https://docs.mulesoft.com/dataweave/2.11/dw-coercions-functions-todatetime">toDateTime</a></p></td><td><p>Transforms a <code>String</code> value into a <code>DateTime</code> value using the first <code>Formatter</code> that matches with the given value to transform.</p></td></tr><tr><td><p><a href="https://docs.mulesoft.com/dataweave/2.11/dw-coercions-functions-todatetimeornull">toDateTimeOrNull</a></p></td><td><p>Transforms a <code>String</code> value into a <code>DateTime</code> value using the first <code>Formatter</code> that matches with the given value to transform.</p></td></tr><tr><td><p><a href="https://docs.mulesoft.com/dataweave/2.11/dw-coercions-functions-tolocaldatetime">toLocalDateTime</a></p></td><td><p>Transforms a <code>String</code> value into a <code>LocalDateTime</code> value using the first <code>Formatter</code> that matches with the given value to transform.</p></td></tr><tr><td><p><a href="https://docs.mulesoft.com/dataweave/2.11/dw-coercions-functions-tolocaldatetimeornull">toLocalDateTimeOrNull</a></p></td><td><p>Transforms a <code>String</code> value into a <code>LocalDateTime</code> value using the first <code>Formatter</code> that matches with the given value to transform.</p></td></tr><tr><td><p><a href="https://docs.mulesoft.com/dataweave/2.11/dw-coercions-functions-tolocaltime">toLocalTime</a></p></td><td><p>Transforms a <code>String</code> value into a <code>LocalTime</code> value using the first <code>Formatter</code> that matches with the given value to transform.</p></td></tr><tr><td><p><a href="https://docs.mulesoft.com/dataweave/2.11/dw-coercions-functions-tolocaltimeornull">toLocalTimeOrNull</a></p></td><td><p>Transforms a <code>String</code> value into a <code>LocalTime</code> value using the first <code>Formatter</code> that matches with the given value to transform.</p></td></tr><tr><td><p><a href="https://docs.mulesoft.com/dataweave/2.11/dw-coercions-functions-tonumber">toNumber</a></p></td><td><p>Transforms a <code>String</code> value into a <code>Number</code> value using the first <code>Formatter</code> that matches with the given value to transform.</p></td></tr><tr><td><p><a href="https://docs.mulesoft.com/dataweave/2.11/dw-coercions-functions-tonumberornull">toNumberOrNull</a></p></td><td><p>Transforms a <code>String</code> value into a <code>Number</code> value using the first <code>Formatter</code> that matches with the given value to transform.</p></td></tr><tr><td><p><a href="https://docs.mulesoft.com/dataweave/2.11/dw-coercions-functions-toperiod">toPeriod</a></p></td><td><p>Transform a <code>String</code> value into a <code>Period</code> value.</p></td></tr><tr><td><p><a href="https://docs.mulesoft.com/dataweave/2.11/dw-coercions-functions-toregex">toRegex</a></p></td><td><p>Transforms a <code>String</code> value into a <code>Regex</code> value.</p></td></tr><tr><td><p><a href="https://docs.mulesoft.com/dataweave/2.11/dw-coercions-functions-tostring">toString</a></p></td><td><p>A variant of <code>toString</code> that transforms a <code>Number</code> value (whole or decimal) into a <code>String</code> value and accepts a format, locale, and rounding mode value.</p></td></tr><tr><td><p><a href="https://docs.mulesoft.com/dataweave/2.11/dw-coercions-functions-totime">toTime</a></p></td><td><p>Transforms a <code>String</code> value into a <code>Time</code> value using the first <code>Formatter</code> that matches with the given value to transform.</p></td></tr><tr><td><p><a href="https://docs.mulesoft.com/dataweave/2.11/dw-coercions-functions-totimeornull">toTimeOrNull</a></p></td><td><p>Transforms a <code>String</code> value into a <code>Time</code> value using the first <code>Formatter</code> that matches with the given value to transform.</p></td></tr><tr><td><p><a href="https://docs.mulesoft.com/dataweave/2.11/dw-coercions-functions-totimezone">toTimeZone</a></p></td><td><p>Transform a <code>String</code> value into a <code>TimeZone</code> value.</p></td></tr><tr><td><p><a href="https://docs.mulesoft.com/dataweave/2.11/dw-coercions-functions-touri">toUri</a></p></td><td><p>Transforms a <code>String</code> value into a <code>Uri</code> value.</p></td></tr></tbody></table>

## Types

- [Coercions Types](https://docs.mulesoft.com/dataweave/2.11/dw-coercions-types)
