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
- Read the appended err message — it gives the line/column and reason; fix that location.
- Replace tabs with spaces for indentation and keep indentation consistent.
- Quote scalars containing ': ' or leading special characters.
- 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
- Validate YAML with an external linter first.
- Avoid tabs for indentation; use spaces.
- Quote scalars containing special characters.
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
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Unable to stringify YAML: ${err}
- ${err.toString()}
- Unable to parse CSV: ${err}
- No "r" value in the signature JSON
- No "s" value in the signature JSON
AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13).
Data as JSON: /api/errors/0e8a5e06bb342094.
Report an issue: GitHub.