Overview

The Extract YAML Block is designed to parse YAML content from input strings and convert it into JavaScript objects. This block is particularly useful when working with configuration files, data serialization, or any scenario where YAML-formatted data needs to be extracted and processed.

Key Features

  • Extract YAML data from input strings with a specified root property name
  • Convert YAML to JavaScript objects
  • Optional JSONPath querying of extracted YAML
  • Configurable error handling for invalid YAML

Inputs

input
string
required

The string containing YAML data to be extracted.

rootPropertyName
string

The name of the root YAML property to extract. Only available when “Use Root Property Name Input” is enabled in settings.

objectPath
string

A JSONPath query to extract specific data from the YAML object. Only available when “Use Object Path Input” is enabled in settings.

Outputs

output
object | any

The extracted and parsed YAML data. If using an Object Path, this will be the first matching value. If no valid YAML is found or no matches are found, this output will be control-flow-excluded.

matches
any[]

When using an Object Path, this contains all values that match the path query. Only available when an Object Path is specified.

noMatch
string

The raw YAML text that was attempted to be parsed, only output when parsing fails or no matches are found.

Editor Settings

rootPropertyName
string
default:"yamlDocument"

The name of the root YAML property to extract. The input text must have this property name followed by a colon somewhere in it.

useRootPropertyNameInput
boolean
default:false

When enabled, allows the root property name to be provided via an input port instead of being set in the settings.

objectPath
string

A JSONPath query to extract specific data from the YAML object. Uses JSONPath syntax.

useObjectPathInput
boolean
default:false

When enabled, allows the object path to be provided via an input port instead of being set in the settings.

Example: Extracting YAML from a Configuration File

  1. Create a new flow and add a Text Block with YAML content that includes a root property name (e.g., yamlDocument:).
  2. Add an Extract YAML Block and connect the Text Block’s output to its input.
  3. Configure the root property name and optional object path in the settings.
  4. Connect the outputs to view the extracted and parsed YAML data.
  5. Run the flow to see the results.

Error Handling

  • If no valid YAML is found under the specified root property name, the output will be control-flow-excluded and noMatch will contain the raw text.
  • If an object path is specified but no matches are found, the output will be control-flow-excluded.
  • If the YAML parsing fails, the output will be control-flow-excluded and noMatch will contain the attempted YAML text.

FAQ

See Also