Skip to main content

Extract YAML Node

Extract YAML Node Screenshot

Overview

The Extract YAML Node is used to parse a YAML object from a string. It is particularly useful when you want to extract structured data from a text string that includes a YAML object.

The node looks for a predefined root property name in the input text and considers all indented text after that as part of the YAML object. By default, the root property name is set to yamlDocument, but it can be configured in the node settings or via an input port.

You may also specify a path to a specific property in the YAML object using a JSONPath expression. The node will then extract the value of that property from the YAML object. This is a shorthand for using the Extract Object Path Node after the Extract YAML Node.

Note that the entire document includes the root property name. For example, if the root property name is set to yamlDocument, then the object path $.yamlDocument will return the entire document.

The Extract YAML Node can only extract a single YAML object from a string. If you want to extract multiple YAML objects from a string, you may want to use the Code Node or External Call Node to do more advanced text extraction.

Text outside of the YAML object will be ignored. If you want to extract text outside of the YAML object, you can use the Extract with Regex Node instead.

Inputs

TitleData TypeDescriptionDefault ValueNotes
InputstringThe string that contains the YAML object.(required)The input will be coerced into a string if it is not a string.
Root Property NamestringThe root property name of the YAML object in the input string.(optional)The input will be coerced into a string if it is not a string. This input is only available if enabled in the node settings.
Object PathstringThe JSONPath expression to extract data from the parsed YAML object.(optional)The input will be coerced into a string if it is not a string. This input is only available if enabled in the node settings.

Example 1: Extract a YAML object from a string

  1. Create a Text Node and set the text to the following:

    yamlDocument:
    name: John Doe
    age: 30
    job: Engineer
  2. Create an Extract YAML Node and connect the Text Node to its Input input.

  3. Run the graph. The Output of the Extract YAML Node should contain the parsed YAML object.

Extract YAML Node Example 1

Example 2: Extract a property from a YAML object

  1. Create a Text Node and set the text to the following:

    yamlDocument:
    name: John Doe
    age: 30
    job: Engineer
  2. Create an Extract YAML Node and connect the Text Node to its Input input.

  3. Set the Object Path of the Extract YAML Node to $.yamlDocument.name.

  4. Run the graph. The Output of the Extract YAML Node should contain the value John Doe.

Extract YAML Node Example 2

Error Handling

If the JSONPath expression is invalid, the Extract YAML Node will error. If the YAML object or the value is not found, the Output and Matches outputs will not be ran, and the No Match output will run with the full contents of the input string.

FAQ

Q: Can I use the Extract YAML Node to extract data from a JSON object?

A: No, the Extract YAML Node is specifically designed to parse YAML objects. If you want to extract data from a JSON object, you can use the Extract JSON Node instead.

Q: Can I use the Extract YAML Node to extract an array from a YAML object?

A: Yes, you can use the Extract YAML Node to extract any valid YAML structure, including arrays. You can use a JSONPath expression to specify the path to the array in the YAML object. Alternatively you can specify a multi-match such as $.yamlDocument.someArray[*] and use the Matches output to get all the matches.

See Also