Loading

How to include line breaks in the value of a field that is defined in YAML format​​​​​​​

Publiseringsdato: Mar 2, 2024
Trinn

QUESTION

How to include line breaks in the value of a field that is defined in YAML format

ANSWER

In a simple Key-Value pair definition of field values in YAML files/payload, the parsers would exclude linebreaks and a few other specific formattings on the field values. If these needs to be retained then the fields must be specially defined. Consider the following example in config.yaml file
input: 
  example1: "a 
      b
      c
      d
      e
      f
      g 
      h"
  example2: |-
      a
      b
      c
      d
      e
      f
      g
      h
When attempting to print both the variables(${input.example1} and ${input.example2}) in a Mule application the following would be the output
INFO  2022-09-20 16:11:41,764 [[MuleRuntime].uber.03: [formatyaml].formatyamlFlow.CPU_LITE @5a6d4819] [processor: formatyamlFlow/processors/0; event: 96586d10-3939-11ed-b0ca-38f9d3aeba7e] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: #############################################
INFO  2022-09-20 16:11:41,766 [[MuleRuntime].uber.03: [formatyaml].formatyamlFlow.CPU_LITE @5a6d4819] [processor: formatyamlFlow/processors/1; event: 96586d10-3939-11ed-b0ca-38f9d3aeba7e] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: a b c d e f g h
INFO  2022-09-20 16:11:41,766 [[MuleRuntime].uber.03: [formatyaml].formatyamlFlow.CPU_LITE @5a6d4819] [processor: formatyamlFlow/processors/2; event: 96586d10-3939-11ed-b0ca-38f9d3aeba7e] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: #############################################
INFO  2022-09-20 16:11:41,767 [[MuleRuntime].uber.03: [formatyaml].formatyamlFlow.CPU_LITE @5a6d4819] [processor: formatyamlFlow/processors/3; event: 96586d10-3939-11ed-b0ca-38f9d3aeba7e] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: a
b
c
d
e
f
g
h
 

ADDITIONAL INFORMATION

The YAML format does not handle the linebreaks and other indentations by default. The definition input.example2 has special handling |- causing the parsers to include linebreaks.

StackOverFlow - How do I break a string in YAML over multiple lines?
Scalars
Knowledge-artikkelnummer

001116383

 
Laster
Salesforce Help | Article