gchq/CyberChef · error · OperationError

Unable to parse YAML: ${err}

Error message

Unable to parse YAML: ${err}

What it means

Thrown by YAMLToJSON.run when the js-yaml load(input) call raises. The catch wraps any parse exception into 'Unable to parse YAML: ' + err, preserving the js-yaml message (which usually names the line/column and the offending construct).

Source

Thrown at src/core/operations/YAMLToJSON.mjs:40

        this.name = "YAML to JSON";
        this.module = "Default";
        this.description = "Convert YAML to JSON";
        this.infoURL = "https://en.wikipedia.org/wiki/YAML";
        this.inputType = "string";
        this.outputType = "JSON";
        this.args = [];
    }

    /**
     * @param {string} input
     * @param {Object[]} args
     * @returns {JSON}
     */
    run(input, args) {
        try {
            return load(input);
        } catch (err) {
            throw new OperationError("Unable to parse YAML: " + err);
        }
    }

}

export default YAMLToJSON;

View on GitHub (pinned to 4290ea7539)

Solutions

  1. Read the appended err message — it gives the line/column and reason; fix that location.
  2. Replace tabs with spaces for indentation and keep indentation consistent.
  3. Quote scalars containing ': ' or leading special characters.
  4. Validate the YAML with an external linter before pasting.

Example fix

// before (tab indentation / bad mapping)
chef.bake("key:\tvalue\nbad: : colon", [{op:"YAML to JSON"}]);
// after
chef.bake("key: value\nbad: ': colon'", [{op:"YAML to JSON"}]);
Defensive patterns

Strategy: validation

Validate before calling

import { load } from "js-yaml";
function safeYamlToJson(s) { try { return load(s); } catch (e) { throw new Error("YAML parse failed: "+e.message); } }

Type guard

const looksLikeYaml = (s) => typeof s === "string" && /^\s*[^\s#].*:\s/m.test(s);

Try / catch

try { result = chef.bake(yaml, [{op:"YAML to JSON"}]); } catch (e) { if (/Unable to parse YAML/.test(e.message)) { /* fix the line/column cited in err */ } else throw e; }

Prevention

When it happens

Trigger: The input is not valid YAML: bad indentation, tabs where spaces are required, unquoted special characters (:, {, }, *), duplicate keys, or undefined aliases/anchors.

Common situations: Feeding JSON-ish text with trailing commas; mixing tabs and spaces; pasting YAML that uses tab indentation; documents with multiple '---' separators that are not well-formed.

Understand the failure class

Related errors


AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13). Data as JSON: /api/errors/0e8a5e06bb342094. Report an issue: GitHub.