Overview
This node provides functionality to parse YAML strings into JSON objects or to convert JSON data into YAML strings. It is useful in workflows where data interchange between YAML and JSON formats is required, such as integrating with systems that use YAML configuration files or APIs that accept YAML input.
Common scenarios include:
- Parsing YAML configuration files or snippets into JSON for further processing.
- Converting JSON data into YAML format for exporting or sending to services expecting YAML.
For example, you can input a YAML string representing a configuration, parse it into JSON to manipulate or validate it within the workflow, then optionally stringify it back to YAML after modifications.
Properties
| Name | Meaning |
|---|---|
| Operation | Choose between "Parse" (convert YAML string to JSON) or "Stringify" (convert JSON to YAML string). |
| YAML / Value | The YAML string to parse (for Parse operation) or the JSON value to stringify (for Stringify operation). |
| Property Name | The name of the property in the output JSON where the result (parsed object or YAML string) will be stored. Default is "data". |
Output
The node outputs an array of items, each containing:
json: The original input JSON merged with a new property (named as per the "Property Name" input) holding either:- The parsed JSON object (if operation is Parse).
- The YAML string representation (if operation is Stringify).
binary(optional): If the input item contains binary data, it is preserved and passed through unchanged.
Example output JSON structure when parsing YAML with Property Name set to "data":
{
"data": {
"key": "value",
"list": [1, 2, 3]
}
}
When stringifying JSON with Property Name "yamlOutput":
{
"yamlOutput": "key: value\nlist:\n - 1\n - 2\n - 3\n"
}
Dependencies
- Uses the external
yamllibrary for parsing and stringifying YAML. - Uses
lodashfor safely setting nested properties in the output JSON. - Requires no special credentials or environment variables.
Troubleshooting
- Parsing errors: If the YAML string is malformed, the node will throw an error indicating the problem location unless "Continue On Fail" is enabled.
- Invalid input for stringification: Providing non-serializable values may cause errors during stringification.
- To resolve errors, ensure the YAML input is valid and the JSON input for stringification is serializable.
Links and References
- YAML specification: https://yaml.org/spec/
yamlnpm package documentation: https://eemeli.org/yaml/