---
schema_version: "1"
id: 23e0dfb62802df5fb85118714d6119ed2136538ebb175271a634973b7362dd9f
title: DataWeave Support in Omni Gateway Policies
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/gateway/latest/policies-dataweave-support.md
canonical_url: https://docs.mulesoft.com/gateway/latest/policies-dataweave-support
source_site: docs.mulesoft.com
content_type: documentation
content_hash: c074f80bd90a16b8a2d426a2d6cbc4667a2b2f6e2a0dfb3a812b12dcd4e42a4d
description: MuleSoft Documentation Site
release: "1.14"
latest: true
---
# DataWeave Support in Omni Gateway Policies

[DataWeave](https://docs.mulesoft.com/dataweave/latest/) is the programming language designed by MuleSoft for data transformation. It enables you to build a simple solution for a common integration developer use case: read and parse data from one format, transform the data, and write it out as a different format.

Omni Gateway supports a subset of DataWeave in policy configuration expressions. DataWeave is only supported in included policies and custom policies created with PDK..

## [](#available-types)Available Types

- [`Null`](https://docs.mulesoft.com/dataweave/latest/dataweave-type-system#null)
- `Boolean`
- `String`
- `Number` (Driven as 64 bits floating points)
- [`Array`](https://docs.mulesoft.com/dataweave/latest/dataweave-type-system#array-type)
- [`Object`](https://docs.mulesoft.com/dataweave/latest/dataweave-type-system#object-type) (Repeated keys are not available)

## [](#available-value-constructors-for-types)Available Value Constructors for Types

- [`Boolean`](https://docs.mulesoft.com/dataweave/latest/dataweave-types#dw_type_boolean)
- [`String`](https://docs.mulesoft.com/dataweave/latest/dataweave-types#dw_type_string)
- [`Null`](https://docs.mulesoft.com/dataweave/latest/dataweave-types#dw_type_null)
- [`Number`](https://docs.mulesoft.com/dataweave/latest/dataweave-types#dw_type_number)
- [`Array`](https://docs.mulesoft.com/dataweave/latest/dataweave-types#dw_type_array)

## [](#unavailable-value-constructors-for-types)Unavailable Value Constructors for Types

- [`Object`](https://docs.mulesoft.com/dataweave/latest/dataweave-types#dw_type_object) (Objects can not be defined as literals)

## [](#available-flow-control-structures)Available Flow Control Structures

- [`if else`](https://docs.mulesoft.com/dataweave/latest/dataweave-flow-control#control_flow_if_else)

## [](#unavailable-flow-control-structures)Unavailable Flow Control Structures

- [`do`](https://docs.mulesoft.com/dataweave/latest/dataweave-flow-control#control_flow_do)

## [](#available-selectors)Available Selectors

- `Array[Number]`
- `Array[String]`
- `Object[String]`
- `String[Number]`

## [](#unavailable-selectors)Unavailable Selectors

- `Object[Number]`

## [](#available-equality-and-relational-operators)Available Equality and Relational Operators

- [`==`](https://docs.mulesoft.com/dataweave/latest/dw-operators#equality-and-relational-operators)
- [`!=`](https://docs.mulesoft.com/dataweave/latest/dw-operators#equality-and-relational-operators)
- [`>=`](https://docs.mulesoft.com/dataweave/latest/dw-operators#equality-and-relational-operators)
- [`<=`](https://docs.mulesoft.com/dataweave/latest/dw-operators#equality-and-relational-operators)

## [](#available-logical-operators)Available Logical Operators

- [`not`](https://docs.mulesoft.com/dataweave/latest/dw-operators#logical_operators)
- [`and`](https://docs.mulesoft.com/dataweave/latest/dw-operators#logical_operators)
- [`or`](https://docs.mulesoft.com/dataweave/latest/dw-operators#logical_operators)

## [](#available-default-operators)Available Default Operators

- [`default`](https://docs.mulesoft.com/dataweave/latest/dataweave-cookbook-defaults#example-of-using-the-keyword-default-to-set-a-default-value)

## [](#available-functions)Available Functions

### [](#)`++`

- [`++(Array<S>, Array<T>): Array<S | T>`](https://docs.mulesoft.com/dataweave/latest/dw-core-functions-plusplus#plusplus1)
- [`++(String, String): String`](https://docs.mulesoft.com/dataweave/latest/dw-core-functions-plusplus#plusplus2)

### [](#available-minus-operators)`--`

- [`--<S>(source: Array<S>, toRemove: Array<Any>): Array<S>`](https://docs.mulesoft.com/dataweave/latest/dw-core-functions-minusminus#minusminus1)
- [`--<K, V>(source: { (K)?: V }, toRemove: Object): { (K)?: V }`](https://docs.mulesoft.com/dataweave/latest/dw-core-functions-minusminus#minusminus2)
- [`--(source: Object, keys: Array<String>)`](https://docs.mulesoft.com/dataweave/latest/dw-core-functions-minusminus#minusminus3)

### [](#contains)`contains`

- [`contains(Array<T>, Any): Boolean`](https://docs.mulesoft.com/dataweave/latest/dw-core-functions-contains#contains1)
- [`contains(String, String): Boolean`](https://docs.mulesoft.com/dataweave/latest/dw-core-functions-contains#contains2)

### [](#lower)`lower`

- [`lower(String): String`](https://docs.mulesoft.com/dataweave/latest/dw-core-functions-lower#lower1)
- [`lower(Null): Null`](https://docs.mulesoft.com/dataweave/latest/dw-core-functions-lower#lower2)

### [](#splitby)`splitBy`

- [`splitBy(String, String): Array<String>`](https://docs.mulesoft.com/dataweave/latest/dw-core-functions-splitby#splitby2)

### [](#sizeof)`sizeOf`

- [`sizeOf(Array<Any>): Number`](https://docs.mulesoft.com/dataweave/latest/dw-core-functions-sizeof#sizeof1)
- [`sizeOf(Object): Number`](https://docs.mulesoft.com/dataweave/latest/dw-core-functions-sizeof#sizeof2)
- [`sizeOf(String): Number`](https://docs.mulesoft.com/dataweave/latest/dw-core-functions-sizeof#sizeof4)

### [](#trim)`trim`

- [`trim(String): String`](https://docs.mulesoft.com/dataweave/latest/dw-core-functions-trim#trim1)
- [`trim(Null): Null`](https://docs.mulesoft.com/dataweave/latest/dw-core-functions-trim#trim2)

### [](#upper)`upper`

- [`upper(String): String`](https://docs.mulesoft.com/dataweave/latest/dw-core-functions-upper#upper1)
- [`upper(Null): Null`](https://docs.mulesoft.com/dataweave/latest/dw-core-functions-upper#upper2)

### [](#uuid)`uuid`

- [`uuid(): String`](https://docs.mulesoft.com/dataweave/latest/dw-core-functions-uuid#uuid1)

### [](#dwcorestringssubstringafter)`dw::core::Strings::substringAfter`

- [`substringAfter(String, String): String`](https://docs.mulesoft.com/dataweave/latest/dw-strings-functions-substringafter#substringafter1)
- [`substringAfter(Null, String): Null`](https://docs.mulesoft.com/dataweave/latest/dw-strings-functions-substringafter#substringafter2)

### [](#dwcorestringssubstringafterlast)`dw::core::Strings::substringAfterLast`

- [`substringAfterLast(String, String): String`](https://docs.mulesoft.com/dataweave/latest/dw-strings-functions-substringafterlast#substringafterlast1)
- [`substringAfterLast(Null, String): Null`](https://docs.mulesoft.com/dataweave/latest/dw-strings-functions-substringafterlast#substringafterlast2)

### [](#dwcorestringssubstringbefore)`dw::core::Strings::substringBefore`

- [`substringBefore(String, String): String`](https://docs.mulesoft.com/dataweave/latest/dw-strings-functions-substringbefore#substringbefore1)
- [`substringBefore(Null, String): Null`](https://docs.mulesoft.com/dataweave/latest/dw-strings-functions-substringbefore#substringbefore2)

### [](#dwcorestringssubstringbeforelast)`dw::core::Strings::substringBeforeLast`

- [`substringBeforeLast(text: String, separator: String): String`](https://docs.mulesoft.com/dataweave/latest/dw-strings-functions-substringbeforelast#substringbeforelast1)
- [`substringBeforeLast(text: Null, separator: String): Null`](https://docs.mulesoft.com/dataweave/latest/dw-strings-functions-substringbeforelast#substringbeforelast2)

### [](#tobase64)toBase64

- [`toBase64(content: Binary): String`](https://docs.mulesoft.com/dataweave/latest/dw-binaries-functions-tobase64#tobase641)

### [](#frombase64)fromBase64

- [`fromBase64(base64String: String): Binary`](https://docs.mulesoft.com/dataweave/latest/dw-binaries-functions-frombase64#frombase641)

<table>
<tbody><tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
<div class="paragraph">
<p>Omni Gateway doesn’t support DataWeave expressions with binary type results. To use the <code>dw::Binaries::fromBase64('dXNlcjpwYXNz')</code> function, transform the result to a string. Transform the binary output to a string with the <code>dw::util::Coercions::toString(binary: Binary, encoding: String): String</code> function. For example, <code><mark>[dw::util::Coercions::toString(dw::core::Binaries::fromBase64('dXNlcjpwYXNz'), 'UTF-8')]</mark></code>.
If using a different function that transforms the binary by default, such as <code>[splitBy(dw::core::Binaries::fromBase64('dXNlcjpwYXNz'), ':')]</code>, you can skip manually transforming the binary.</p>
</div>
</td>
</tr>
</tbody></table>

### [](#tobinary)toBinary

- [`toBinary(str: String, encoding: String): Binary`](https://docs.mulesoft.com/dataweave/latest/dw-coercions-functions-tobinary#tobinary1)

### [](#tostring)toString

- [`toString(binary: Binary, encoding: String): String`](https://docs.mulesoft.com/dataweave/latest/dw-coercions-functions-tostring#tostring3)

## [](#available-predefined-variables)Available Predefined Variables

- [`attributes`](https://docs.mulesoft.com/dataweave/latest/dataweave-variables-context)
    
    - `attributes.headers`
    - `attributes.method` (Only available in request context)
    - `attributes.queryParams` (Only available in request context)
    - `attributes.queryString` (Only available in request context)
    - `attributes.requestPath` (Only available in request context)
    - `attributes.requestUri` (Only available in request context)
    - `attributes.localAddress` (Only available in request context)
    - `attributes.remoteAddress` (Only available in request context)
    - `attributes.scheme` (Only available in request context)
    - `attributes.version` (Only available in request context)
    - `attributes.statusCode` (Only available in response context)
- [`authentication`](https://docs.mulesoft.com/dataweave/latest/dataweave-variables-context)
    
    - `authentication.clientId`
    - `authentication.clientName`
    - `authentication.principal`
    - `authentication.properties`
        
        To learn more about how to access the authentication object, see [Access the Authentication Object](#access-authentication-object).
- `payload`
    
    - Fields depend on the current payload. For example, `#[payload]` returns the body of the message.
- [`vars`](https://docs.mulesoft.com/dataweave/latest/dataweave-variables-context)
    
    - Individual policies support different sets of variables. For information, refer to the policies listed in [Inbound Policies Directory](https://docs.mulesoft.com/gateway/latest/policies-included-directory).

## [](#dataweave-usage-examples)DataWeave Usage Examples

You can use DataWeave to extract different values from the request and response.

<table><tbody><tr><td class="icon"><i class="fa icon-note" title="Note"></i></td><td class="content">The Omni Gateway Policy Development Kit (PDK) provides the <a href="https://github.com/mulesoft/pdk-custom-policy-examples/tree/main/dataweave">DataWeave example policy</a> that you can use to test DataWeave expressions.</td></tr></tbody></table>

For example, use DataWeave expressions to:

- Read a header:
    
    #\[attributes.headers.'my-header'\]
- Ensure a specific header is defined:
    
    #\[attributes.headers.'my-header' != null\]
- Check if a request has basic authorization:
    
    #\[lower(splitBy(attributes.headers.authorization default '', ' ')\[0\]) == 'basic'\]
- Check if a request contains `/some` path:
    
    #\[attributes.requestPath contains '/some'\]
- Check if a request doesn’t contain `/some` path:
    
    #\[not(attributes.requestPath contains '/some')\]
- Read the username from a `Basic` authorization header:
    
    #\[splitBy(dw::core::Binaries::fromBase64(dw::core::Strings::substringAfter(attributes.headers.authorization default '', 'Basic')), ':')\[0\]\]
- Read the password from a `Basic` authorization header:
    
    #\[splitBy(dw::core::Binaries::fromBase64(dw::core::Strings::substringAfter(attributes.headers.authorization default '', 'Basic ')), ':')\[1\]\]
- Read the first value of the `x-forwarded-for` header:
    
    #\[trim(splitBy(attributes.headers.'x-forwarded-for', ',')\[0\])\]
- Read the last value of the `x-forwarded-for` header:
    
    #\[trim(splitBy(attributes.headers.'x-forwarded-for', ',')\[-1\])\]
- Read the value from a `Cookie`:
    
    #\[trim(dw::core::Strings::substringBefore(dw::core::Strings::substringAfter(attributes.headers.Cookie default '', 'myCookieName='), ';'))\]
- Check if a single value or space-separated header contains a specific value:
    
    #\[splitBy(attributes.headers.scopes default '', ' ') contains 'read'\]

## [](#access-authentication-object)Access the Authentication Object

To access the [`authentication`](https://docs.mulesoft.com/dataweave/latest/dataweave-variables-context) object, you must first configure an authentication policy that populates the object.

The authentication policy you apply affects the available authentication object properties:

- Multiple policies can validate Client ID:
    
    - [Client ID Enforcement Policy](https://docs.mulesoft.com/gateway/latest/policies-included-client-id-enforcement)
    - [Rate Limiting: SLA-Based Policy](https://docs.mulesoft.com/gateway/latest/policies-included-rate-limiting-sla)
    - [OAuth 2.0 Token Introspection Policy](https://docs.mulesoft.com/gateway/latest/policies-included-oauth-token-introspection) (If Client ID enforcement is configured)
    - [OpenID Connect OAuth 2.0 Token Enforcement Policy](https://docs.mulesoft.com/gateway/latest/policies-included-openid-token-enforcement) (If Client ID enforcement is configured)
    - [JWT Validation Policy](https://docs.mulesoft.com/gateway/latest/policies-included-jwt-validation) (If Client ID enforcement is configured)
        
        Policies validating Client ID provide these authentication object properties:
        
        - `authentication.clientName`: Name of the contract’s client application
        - `authentication.clientId`: ID of the contract’s client application
        - `authentication.properties.slaId`: SLA ID assigned to the contract
- [JWT Validation Policy](https://docs.mulesoft.com/gateway/latest/policies-included-jwt-validation):
    
    - `authentication.properties.claims.<claimName>`: All claims provided by the JWT
- Multiple policies validate basic authentication credentials:
    
    - [Basic Authentication: Simple Policy](https://docs.mulesoft.com/gateway/latest/policies-included-basic-auth-simple)
    - [Basic Authentication: LDAP Policy](https://docs.mulesoft.com/gateway/latest/policies-included-basic-auth-ldap)
        
        Policies validating basic authentication credentials provide these authentication object properties:
        
        - `authentication.principal`: Username passed as basic auth user

After your policy populates the authentication object, you can access the object in policies ordered after the authentication policy using DataWeave expressions. For example:

- Read a value from the authentication object:
    
    #\[authentication.properties.claims.exp\]
- Check if a JSON array or a JSON string JWT claim contains a specific value:
    
    #\[authentication.properties.claims.custom\_claim contains 'read'\]
- Remove sensitive headers, such as `Authorization`, for logging purposes:
    
    #\[attributes.headers -- "Authorization"\]