Contact Us 1-800-596-4880

YAML Format

MIME type: application/yaml

ID: yaml

Values in the YAML data format map one-to-one with DataWeave values. DataWeave natively supports all of the following YAML types:

  • String

  • Boolean

  • Number

  • Nil

  • Mapping

  • Sequences

Example: Represent YAML in the DataWeave Format (dw)

This example shows how DataWeave represents YAML values.

Input

The following YAML snippet serves as the input payload for the DataWeave source in this example.

american:
  - Boston Red Sox
  - Detroit Tigers
  - New York Yankees
national:
  - New York Mets
  - Chicago Cubs
  - Atlanta Braves

Source

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

%dw 2.0
output application/dw
---
payload

Output

The following output shows how the YAML input is represented in the DataWeave (dw) format.

{
  "american": [
    "Boston Red Sox",
    "Detroit Tigers",
    "New York Yankees"
  ],
  "national": [
    "New York Mets",
    "Chicago Cubs",
    "Atlanta Braves"
  ]
}

Configuration Properties

DataWeave supports the following configuration properties for this format.

Reader Properties

This format accepts properties that provide instructions for reading input data.

Parameter Type Default Description

maxEntityCount

Number

1

Sets the maximum number of entity expansions. The limit helps avoid Billion Laughs attacks.

Writer Properties

This format accepts properties that provide instructions for writing output data.

Parameter Type Default Description

bufferSize

Number

8192

Size of the buffer writer, in bytes. The value must be greater than 8.

deferred

Boolean

false

Generates the output as a data stream when set to true, and defers the script’s execution until the generated content is consumed.

Valid values are true or false.

encoding

String

'UTF-8'

The encoding to use for the output, such as UTF-8.

skipNullOn

String

null

Skips null values in the specified data structure. By default, DataWeave does not skip the values.

  • arrays + Ignore and omit null values inside arrays from the YAML output, for example, with output application/yaml skipNullOn="arrays".

  • objects + Ignore key-value pairs that have null as the value, for example, with output application/yaml skipNullOn="objects".

  • everywhere + Apply skipNullOn to arrays and objects, for example, output application/yaml skipNullOn="everywhere".

Valid values are arrays or objects or everywhere.

writeDeclaration

Boolean

true

Indicates whether to write the header declaration or not.

Valid values are true or false.

Supported MIME Types

This format supports the following MIME types.

MIME Type

application/yaml

text/yaml

application/x-yaml

text/x-yaml