{"record":{"id":"62a93d49812e9f69","repo":"mikefarah/yq","slug":"bad-expression-could-not-find-matching-62a93d","errorCode":null,"errorMessage":"bad expression, could not find matching `}`","messagePattern":"bad expression, could not find matching `\\}`","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/yqlib/expression_postfix.go","lineNumber":32,"sourceCode":"}\n\nfunc newExpressionPostFixer() expressionPostFixer {\n\treturn &expressionPostFixerImpl{}\n}\n\nfunc popOpToResult(opStack []*token, result []*Operation) ([]*token, []*Operation) {\n\tvar newOp *token\n\topStack, newOp = opStack[0:len(opStack)-1], opStack[len(opStack)-1]\n\tlog.Debugf(\"popped %v from opstack to results\", newOp.toString(true))\n\treturn opStack, append(result, newOp.Operation)\n}\n\nfunc validateNoOpenTokens(token *token) error {\n\tswitch token.TokenType {\n\tcase openCollect:\n\t\treturn fmt.Errorf((\"bad expression, could not find matching `]`\"))\n\tcase openCollectObject:\n\t\treturn fmt.Errorf((\"bad expression, could not find matching `}`\"))\n\tcase openBracket:\n\t\treturn fmt.Errorf((\"bad expression, could not find matching `)`\"))\n\t}\n\treturn nil\n}\n\nfunc (p *expressionPostFixerImpl) ConvertToPostfix(infixTokens []*token) ([]*Operation, error) {\n\tvar result []*Operation\n\t// surround the whole thing with brackets\n\tvar opStack = []*token{{TokenType: openBracket}}\n\tvar tokens = append(infixTokens, &token{TokenType: closeBracket})\n\n\tfor _, currentToken := range tokens {\n\t\tlog.Debugf(\"postfix processing currentToken %v\", currentToken.toString(true))\n\t\tswitch currentToken.TokenType {\n\t\tcase openBracket, openCollect, openCollectObject:\n\t\t\topStack = append(opStack, currentToken)\n\t\t\tlog.Debugf(\"put %v onto the opstack\", currentToken.toString(true))","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/mikefarah/yq/blob/8b5af0694bb82b41d4ae180fac9972029066f90a/pkg/yqlib/expression_postfix.go#L14-L50","documentation":"validateNoOpenTokens finds an unclosed openCollectObject token ('{') at the end of conversion. An object-collect was opened in the expression but never closed with '}', so the expression is incomplete and rejected.","triggerScenarios":"Running `yq '{a: .a' file.yml` or expressions like `{\"key\": .value}` missing the closing brace, often from truncated quoting.","commonSituations":"Building object-collect expressions dynamically in scripts, shell variable expansion swallowing the `}` (brace expansion!), multi-line edits.","solutions":["Add the matching `}` to close the object collect (e.g. `{a: .a}`)","Single-quote the expression to prevent shell brace expansion from interfering","Check templates/heredocs that generate the expression for dropped braces"],"exampleFix":"// before\nyq '{a: .a' file.yml\n// after\nyq '{a: .a}' file.yml","handlingStrategy":"validation","validationCode":"depth := strings.Count(expr, \"{\") - strings.Count(expr, \"}\")\nif depth != 0 {\n    return fmt.Errorf(\"unbalanced { } in expression %q\", expr)\n}","typeGuard":null,"tryCatchPattern":"out, err := runYq(expr, file)\nif err != nil && strings.Contains(err.Error(), \"could not find matching `}`\") {\n    return fmt.Errorf(\"unclosed { in expression %q\", expr)\n}","preventionTips":["Beware shell brace expansion: always single-quote yq expressions containing `{}`","Write object collects in one line first, then extend","Template-generated expressions: assert braces survive substitution"],"tags":["expression","bracket","syntax"],"backgroundTag":"unclosed-bracket-expression","analyzedSha":"8b5af0694bb82b41d4ae180fac9972029066f90a","analyzedAt":"2026-09-05T10:57:22.766Z","contentChangedAt":"2026-09-05T10:57:22.766Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}