{"record":{"id":"fe2517f13f2e9060","repo":"grpc-ecosystem/grpc-gateway","slug":"s-q-w","errorCode":null,"errorMessage":"%s: %q: %w","messagePattern":"(.+?): %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"openapiv3-merge/internal/merge/merge.go","lineNumber":201,"sourceCode":"\ttok, err := dec.Token()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"%s: %w\", in.Name, err)\n\t}\n\tif delim, ok := tok.(json.Delim); !ok || delim != '{' {\n\t\treturn nil, fmt.Errorf(\"%s: expected JSON object at top level\", in.Name)\n\t}\n\tfor dec.More() {\n\t\ttok, err := dec.Token()\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"%s: %w\", in.Name, err)\n\t\t}\n\t\tkey, ok := tok.(string)\n\t\tif !ok {\n\t\t\treturn nil, fmt.Errorf(\"%s: unexpected token %v\", in.Name, tok)\n\t\t}\n\t\tvar raw json.RawMessage\n\t\tif err := dec.Decode(&raw); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"%s: %q: %w\", in.Name, key, err)\n\t\t}\n\t\tswitch key {\n\t\tcase \"openapi\":\n\t\t\tif err := json.Unmarshal(raw, &d.OpenAPI); err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"%s: openapi: %w\", in.Name, err)\n\t\t\t}\n\t\tcase \"info\":\n\t\t\td.Info = raw\n\t\tcase \"servers\":\n\t\t\td.Servers = raw\n\t\tcase \"paths\":\n\t\t\tobj, err := decodeOrderedObject(raw)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"%s: paths: %w\", in.Name, err)\n\t\t\t}\n\t\t\td.Paths = obj\n\t\tcase \"webhooks\":\n\t\t\tobj, err := decodeOrderedObject(raw)","sourceCodeStart":183,"sourceCodeEnd":219,"githubUrl":"https://github.com/grpc-ecosystem/grpc-gateway/blob/a58a4436a376a4bcc7d8f10c4d4f919a8438bba9/openapiv3-merge/internal/merge/merge.go#L183-L219","documentation":"This error wraps a json.Decoder failure while decoding the VALUE that follows a top-level key (merge.go:199-201). The key was read successfully, but streaming the value into a json.RawMessage failed — the value is malformed (e.g. truncated string, bad number, unclosed array) or the document ends prematurely. It is prefixed with both the input name and the key name (%q) so the offending field is immediately identifiable.","triggerScenarios":"Calling Merge with Input data where some top-level field's value is syntactically invalid JSON — e.g. \"info\": {unclosed..., a truncated paths value, or an unterminated string after \"description\": — causing dec.Decode(&raw) to fail for that key.","commonSituations":"File cut off mid-value by a failed upload/download; templating that left placeholders like {{...}} inside a value; unescaped quotes in a description string produced by a generator; an editor crash leaving a partially saved spec.","solutions":["Look at the key named in the error message and inspect that field's value in the input file for syntax errors.","Run json.Valid / a linter on the input to get the exact byte offset of the malformed value.","Escape or remove raw placeholders and unescaped quotes inside string values before merging.","Re-export or re-download the spec if the file appears truncated mid-value.","For generated specs, fix the generator's JSON serialization instead of post-patching the output."],"exampleFix":"// before\n\"info\": {\"description\": \"uses \"quotes\" unescaped\"}  // invalid\n// after\n\"info\": {\"description\": \"uses \\\"quotes\\\" unescaped\"}","handlingStrategy":"validation","validationCode":"func preValidate(name string, data []byte) error {\n    if !json.Valid(data) {\n        return fmt.Errorf(\"%s: a field value is malformed; run a JSON linter for the exact offset\", name)\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"var syntaxErr *json.SyntaxError\nif err != nil && errors.As(err, &syntaxErr) {\n    // err message is \"<name>: \\\"<key>\\\": ...\" — jump straight to that key in the file\n    log.Printf(\"fix the value of the named key; syntax error at offset %d\", syntaxErr.Offset)\n}","preventionTips":["Escape quotes and control characters inside description-like string fields.","Never leave template placeholders ({{ }}) unresolved inside spec values.","Detect truncation: compare downloaded size against Content-Length before merging.","Lint every generated spec (json.Valid / Spectral) as a pre-merge CI gate."],"tags":["json","parsing","openapi","go"],"backgroundTag":"invalid-json-syntax","analyzedSha":"a58a4436a376a4bcc7d8f10c4d4f919a8438bba9","analyzedAt":"2026-09-02T10:28:31.537Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T16:17:10.729Z"}