{"record":{"id":"0e8a5e06bb342094","repo":"gchq/CyberChef","slug":"unable-to-parse-yaml-err","errorCode":null,"errorMessage":"Unable to parse YAML: ${err}","messagePattern":"Unable to parse YAML: (.+?)","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/YAMLToJSON.mjs","lineNumber":40,"sourceCode":"        this.name = \"YAML to JSON\";\n        this.module = \"Default\";\n        this.description = \"Convert YAML to JSON\";\n        this.infoURL = \"https://en.wikipedia.org/wiki/YAML\";\n        this.inputType = \"string\";\n        this.outputType = \"JSON\";\n        this.args = [];\n    }\n\n    /**\n     * @param {string} input\n     * @param {Object[]} args\n     * @returns {JSON}\n     */\n    run(input, args) {\n        try {\n            return load(input);\n        } catch (err) {\n            throw new OperationError(\"Unable to parse YAML: \" + err);\n        }\n    }\n\n}\n\nexport default YAMLToJSON;\n","sourceCodeStart":22,"sourceCodeEnd":47,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/YAMLToJSON.mjs#L22-L47","documentation":"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).","triggerScenarios":"The input is not valid YAML: bad indentation, tabs where spaces are required, unquoted special characters (:, {, }, *), duplicate keys, or undefined aliases/anchors.","commonSituations":"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.","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."],"exampleFix":"// before (tab indentation / bad mapping)\nchef.bake(\"key:\\tvalue\\nbad: : colon\", [{op:\"YAML to JSON\"}]);\n// after\nchef.bake(\"key: value\\nbad: ': colon'\", [{op:\"YAML to JSON\"}]);","handlingStrategy":"validation","validationCode":"import { load } from \"js-yaml\";\nfunction safeYamlToJson(s) { try { return load(s); } catch (e) { throw new Error(\"YAML parse failed: \"+e.message); } }","typeGuard":"const looksLikeYaml = (s) => typeof s === \"string\" && /^\\s*[^\\s#].*:\\s/m.test(s);","tryCatchPattern":"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; }","preventionTips":["Validate YAML with an external linter first.","Avoid tabs for indentation; use spaces.","Quote scalars containing special characters."],"tags":["yaml","json","parse-error","js-yaml"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}