Contact Free trial Login

URL Encoded Format

MIME Type: application/x-www-form-urlencoded

ID: urlencoded

URL encoded data represents a collection of key-value pairs. DataWeave represents these values as an object in which each value is a string.

Examples

The following examples show uses of the URL Encoded format:

Example: Represent URL Encoded Data in the DataWeave (dw) Format

This example shows how DataWeave represents simple URL encoded data.

Input

The URL encoded data serves as input payload to the DataWeave source.

name=Mariano&lastName=de+Achaval

Source

The DataWeave script transforms the URL encoded input payload to the DataWeave (dw) format and MIME type.

%dw 2.0
output application/dw
---
payload

Output

The output is a DataWeave object that contains a collection of key-value pairs from the input.

{
    "name": "Mariano",
    "lastName": "de Achaval"
}

Example: Generate URL Encoded Data from a JSON Object

This example shows how to generate URL Encoded data.

Input

The JSON object serves as the input payload to the DataWeave source.

{
  "name": "Mariano"
}

Source

The DataWeave script selects the value of the name key in the input payload and transforms all values of the object in the body of the script to the urlencoded format.

%dw 2.0
output urlencoded
---
{
    name: payload.name,
    age: 37
}

Output

The output is URL encoded data that is constructed from the key-value pairs in the body of the DataWeave script.

name=Mariano&age=37

Example: Generate URL Encoded Data from a Collection of Key-Value Pairs

This DataWeave script produces the URL encoded output.

Source

The DataWeave script transforms the format of the JSON input found within the body of the script into the URL Encoded format.

%dw 2.0
output application/x-www-form-urlencoded
---
{
  "key" : "value",
  "key 1": "@here",
  "key" : "other value",
  "key 2%": null
}

Output

The output shows the input data in the URL Encoded format.

key=value&key+1=%40here&key=other+value&key+2%25

Example: Transform URL Encoded Data to the Text Plain Format

This example transforms URL Encoded input into the Text Plain format and MIME type.

Source

The DataWeave script reads the URL Encoded data and concatenates values of the selected keys.

%dw 2.0
var myData  read('key=value&key+1=%40here&key=other+value&key+2%25', 'application/x-www-form-urlencoded')
output text/plain
---
myData.*key[0] ++ myData.'key 1'

Output

The output is in Text Plain format.

value@here

Configuration Properties

DataWeave supports the following configuration properties for the URL Encoded format.

Reader Properties (for URL Encoded Data)

There are no reader properties for URL encoded data.

Writer (for URL Encoded Data)

The URL Encoded format accepts properties that provide instructions for writing output data.

Parameter Type Default Description

bufferSize

Number

8192

Size of the writer buffer.

deferred

Boolean

false

Property for deferred output. Valid values are true or false.

encoding

String

null

Encoding for the writer to use.

Supported MIME Types

The URL Encoded format supports the following MIME types.

MIME Type

application/x-www-form-urlencoded

Was this article helpful?

💙 Thanks for your feedback!

Edit on GitHub