---
schema_version: "1"
id: de77b2caae08efa8f99d5f7c1afd7fb43153a05eb676267a2415a3e056309af2
title: JWT
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/dataweave/latest/dw-hmac-functions-jwt.md
canonical_url: https://docs.mulesoft.com/dataweave/latest/dw-hmac-functions-jwt
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 66389f216b1929fe12a974e7609d701e8447d1542cd73eb7bfa2209375cfdde3
description: MuleSoft Documentation Site
release: "2.13"
latest: true
---
---
product: DataWeave
version: 2.13
is-latest-version: true
---

# JWT

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

## JWT(header: Object, payload: Object, signingKey: String, algorithm: String): String

Generate JWT with header, payload, and signature by specific algorithm.

_Introduced in DataWeave version 2.6.0._

### Parameters

<table><colgroup><col> <col> <col></colgroup><thead><tr><th>Name</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><p><code>header</code></p></td><td><p><code>Object</code></p></td><td><p>JWT header.</p></td></tr><tr><td><p><code>payload</code></p></td><td><p><code>Object</code></p></td><td><p>JWT payload.</p></td></tr><tr><td><p><code>signingKey</code></p></td><td><p><code>String</code></p></td><td><p>Signing key.</p></td></tr><tr><td><p><code>algorithm</code></p></td><td><p><code>String</code></p></td><td><p>HMAC algorithm.</p></td></tr></tbody></table>

### Example

This example signs a payload with HS384 and a 384-bit key.

#### Source

```DataWeave
%dw 2.0
import * from dw::util::jwt::HMAC
output application/json
---
JWT({"header": "value"}, {"firstName": "Michael", "lastName": "Jones"},
  "012345678901234567890123456789012345678901234567", "HmacSHA384")
```

#### Output

```Json
"eyJoZWFkZXIiOiAidmFsdWUiLCJhbGciOiAiSFMzODQiLCJ0eXAiOiAiSldUIn0.eyJmaXJzdE5hbWUiOiAiTWljaGFlbCIsImxhc3ROYW1lIjogIkpvbmVzIn0.F1xP9JjXqmwVfPXULZ7F6EYu2Td36eW4xUWElGHN7ayjWIiBPWM3L4STPQzQ570R"
```

## JWT(header: Object, payload: Object, signingKey: String): String

Generate JWT with a header, payload, and key signed with HMAC-SHA256.

_Introduced in DataWeave version 2.6.0._

### Parameters

<table><colgroup><col> <col> <col></colgroup><thead><tr><th>Name</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><p><code>header</code></p></td><td><p><code>Object</code></p></td><td><p>JWT header.</p></td></tr><tr><td><p><code>payload</code></p></td><td><p><code>Object</code></p></td><td><p>JWT payload.</p></td></tr><tr><td><p><code>signingKey</code></p></td><td><p><code>String</code></p></td><td><p>Signing key.</p></td></tr></tbody></table>

### Example

This example uses HS256 and a 256-bit key.

#### Source

```DataWeave
%dw 2.0
import * from dw::util::jwt::HMAC
output application/json
---
JWT({"header": "value"}, {"firstName": "Michael", "lastName": "Jones"},
  "01234567890123456789012345678901")
```

#### Output

```Json
"eyJoZWFkZXIiOiAidmFsdWUiLCJhbGciOiAiSFMyNTYiLCJ0eXAiOiAiSldUIn0.eyJmaXJzdE5hbWUiOiAiTWljaGFlbCIsImxhc3ROYW1lIjogIkpvbmVzIn0.wAoUwkmKhZy6Op119t0N5MwQX-03fJZClzfA5lFwEhg"
```

## JWT(payload: Object, signingKey: String): String

Generate JWT with a payload, automatically generated header, and key signed with HMAC-SHA256.

_Introduced in DataWeave version 2.6.0._

### Parameters

<table><colgroup><col> <col> <col></colgroup><thead><tr><th>Name</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><p><code>payload</code></p></td><td><p><code>Object</code></p></td><td><p>JWT payload.</p></td></tr><tr><td><p><code>signingKey</code></p></td><td><p><code>String</code></p></td><td><p>Signing key.</p></td></tr></tbody></table>

### Example

This example signs a payload with the default HS256 algorithm.

#### Source

```DataWeave
%dw 2.0
import * from dw::util::jwt::HMAC
output application/json
---
JWT({"firstName": "Michael", "lastName": "Jones"},
  "01234567890123456789012345678901")
```

#### Output

```Json
"eyJhbGciOiAiSFMyNTYiLCJ0eXAiOiAiSldUIn0.eyJmaXJzdE5hbWUiOiAiTWljaGFlbCIsImxhc3ROYW1lIjogIkpvbmVzIn0.JaEz34HXuF4fWg5jM2U9JRnX4vu5twoeDRRg9_anWMc"
```
