YAML icon

YAML

Convert data to YAML or from YAML

Overview

This node provides functionality to convert data between JSON and YAML formats, extract data from YAML, and set values within YAML structures. Specifically, the "Convert to YAML" operation transforms input JSON data into YAML format, which can then be output as files. This is useful in scenarios where workflows require exporting structured data in YAML for configuration files, documentation, or integration with systems that consume YAML.

Practical examples include:

  • Converting API response JSON data into a YAML configuration file.
  • Exporting database query results as YAML files for use in infrastructure-as-code tools.
  • Generating YAML manifests from JSON data for Kubernetes deployments.

Properties

Name Meaning
Mode Determines how the conversion is applied:
- All Items to One File: Converts all input items into a single YAML file.
- Each Item to Separate File: Converts each input item into its own YAML file.
Put Output File in Field The name of the binary field where the resulting YAML file(s) will be stored. For example, "data".
Options Collection of additional options:
- Add Byte Order Mark (BOM): Whether to add a BOM marker at the start of the text file to help some programs read it correctly (only applies for certain encodings).
- Format: Whether to pretty-format the JSON data before conversion for easier reading.
- Encoding: Character encoding used for the output file. Many encodings are supported, including utf8, ascii, base64, and others.
- File Name: Optional name for the output file, e.g., "myFile.json".

Output

The node outputs binary data containing the YAML file(s) generated from the input JSON data. The binary data is placed in the specified output binary field (default "data"). Depending on the selected mode, the output can be:

  • A single YAML file containing all input items combined.
  • Multiple YAML files, one per input item.

The output JSON structure includes metadata about the binary file(s), such as filename and encoding, enabling downstream nodes to access or save the YAML content.

Dependencies

  • No external services or API keys are required.
  • The node relies on internal libraries for YAML and JSON processing.
  • No special environment variables or n8n configurations are necessary beyond standard node setup.

Troubleshooting

  • Common Issues:

    • Incorrect input data format: Input must be valid JSON objects or arrays convertible to YAML.
    • Encoding mismatches: Selecting an unsupported or incorrect encoding may cause file corruption or unreadable output.
    • Missing or incorrect binary property name: Ensure the output binary field name is set correctly to avoid losing the output file.
  • Error Messages:

    • Errors related to parsing input data usually indicate invalid JSON input.
    • Encoding errors suggest unsupported or incompatible character sets.

To resolve these issues:

  • Validate input data format before conversion.
  • Use UTF-8 encoding unless a specific alternative is needed.
  • Double-check the binary property name matches downstream expectations.

Links and References

Discussion