{"record":{"id":"3e02fcbe1840439e","repo":"JuliusBrussee/caveman","slug":"not-valid-json-w","errorCode":null,"errorMessage":"not valid JSON: %w","messagePattern":"not valid JSON: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shrink/shrink.go","lineNumber":243,"sourceCode":"\t\tout[e.name] = profileOf(e.schema)\n\t}\n\treturn out, nil\n}\n\n// --- catalog parsing --------------------------------------------------------\n\ntype toolEntry struct {\n\tname   string\n\traw    []byte         // the tool object's JSON\n\tschema map[string]any // its inputSchema/parameters, if any\n}\n\n// extractTools handles the MCP ({\"tools\":[…]}), OpenAI (array of {function:…} or\n// flat) and {\"functions\":[…]} shapes.\nfunc extractTools(input []byte) ([]toolEntry, error) {\n\tvar top any\n\tif err := json.Unmarshal(input, &top); err != nil {\n\t\treturn nil, fmt.Errorf(\"not valid JSON: %w\", err)\n\t}\n\tvar rawList []any\n\tswitch t := top.(type) {\n\tcase map[string]any:\n\t\tif v, ok := t[\"tools\"].([]any); ok {\n\t\t\trawList = v\n\t\t} else if v, ok := t[\"functions\"].([]any); ok {\n\t\t\trawList = v\n\t\t} else {\n\t\t\trawList = []any{t} // a single tool object\n\t\t}\n\tcase []any:\n\t\trawList = t\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"unsupported catalog shape\")\n\t}\n\n\tvar entries []toolEntry","sourceCodeStart":225,"sourceCodeEnd":261,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/shrink/shrink.go#L225-L261","documentation":"extractTools parses a tool catalog for Lint and SelectionProfile and requires the input to be valid JSON in one of the supported shapes (MCP {\"tools\":[...]}, OpenAI array, or {\"functions\":[...]}). If json.Unmarshal fails, the input is not JSON at all and the parse error is wrapped as 'not valid JSON'.","triggerScenarios":"Calling Lint or SelectionProfile with input that isn't JSON: YAML configs, TOML files, BOM-prefixed files, JSONL (multiple JSON documents), truncated output, or raw prose/log content piped in.","commonSituations":"Pasting a tool list from a Markdown doc including code fences; feeding a YAML MCP server config instead of JSON; shell heredoc with comments; double-encoded JSON (a JSON string containing JSON).","solutions":["Validate the input with `jq . input.json` to see the exact syntax error and fix it","Convert non-JSON formats first (yaml2json, toml2json) before passing to Lint/SelectionProfile","Strip Markdown code fences or BOM from the input file","Ensure the file contains a single JSON document, not JSONL or concatenated documents"],"exampleFix":"// before\ncat server.yaml | caveman-shrink lint -\n// after\nyq -o=json . server.yaml | caveman-shrink lint -","handlingStrategy":"validation","validationCode":"let parsed: unknown\ntry { parsed = JSON.parse(input) } catch (e) { throw new Error(`input is not valid JSON: ${e}`) }","typeGuard":"function isJSON(s: string): boolean { try { JSON.parse(s); return true } catch { return false } }","tryCatchPattern":"tools, err := extractTools(input)\nif err != nil {\n  var sintaxErr *json.SyntaxError\n  if errors.As(err, &sintaxErr) {\n    return fmt.Errorf(\"catalog JSON syntax error at offset %d\", sintaxErr.Offset)\n  }\n  return err\n}","preventionTips":["Validate input with jq/JSON.parse before passing it to Lint or SelectionProfile","Convert YAML/TOML sources to JSON first","Strip BOMs and Markdown code fences from copied content"],"tags":["json","parsing","validation"],"backgroundTag":"json-parse-error","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}