{"record":{"id":"f4f1e3f42102257f","repo":"nats-io/nats-server","slug":"js-invalid-json","errorCode":"JS_INVALID_JSON","errorMessage":"consumer group not specified","messagePattern":"consumer group not specified","errorType":"error_code","errorClass":"JSInvalidJSONError","httpStatus":null,"severity":"error","filePath":"server/jetstream_api.go","lineNumber":3863,"sourceCode":"\t\t\treturn\n\t\t}\n\t}\n\n\tif errorOnRequiredApiLevel(hdr) {\n\t\tresp.Error = NewJSRequiredApiLevelError()\n\t\ts.sendAPIErrResponse(ci, acc, subject, reply, string(msg), s.jsonResponse(&resp))\n\t\treturn\n\t}\n\n\tvar req JSApiConsumerUnpinRequest\n\tif err := json.Unmarshal(msg, &req); err != nil {\n\t\tresp.Error = NewJSInvalidJSONError(err)\n\t\ts.sendAPIErrResponse(ci, acc, subject, reply, string(msg), s.jsonResponse(&resp))\n\t\treturn\n\t}\n\n\tif req.Group == _EMPTY_ {\n\t\tresp.Error = NewJSInvalidJSONError(errors.New(\"consumer group not specified\"))\n\t\ts.sendAPIErrResponse(ci, acc, subject, reply, string(msg), s.jsonResponse(&resp))\n\t\treturn\n\t}\n\n\tif !validGroupName.MatchString(req.Group) {\n\t\tresp.Error = NewJSConsumerInvalidGroupNameError()\n\t\ts.sendAPIErrResponse(ci, acc, subject, reply, string(msg), s.jsonResponse(&resp))\n\t\treturn\n\t}\n\n\tif hasJS, doErr := acc.checkJetStream(); !hasJS {\n\t\tif doErr {\n\t\t\tresp.Error = NewJSNotEnabledForAccountError()\n\t\t\ts.sendAPIErrResponse(ci, acc, subject, reply, string(msg), s.jsonResponse(&resp))\n\t\t}\n\t\treturn\n\t}\n","sourceCodeStart":3845,"sourceCodeEnd":3881,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/jetstream_api.go#L3845-L3881","documentation":"A JSON validation error reported via NewJSInvalidJSONError (code JS_INVALID_JSON) in the distributed consumer-group (durable group) request handler: the request decoded fine but req.Group is empty, and a consumer group name is mandatory for this API. It is intentionally surfaced as an invalid-JSON/invalid-request style error to the client.","triggerScenarios":"Posting a request to the consumer group API ($JS.API.CONSUMER.GROUP style endpoint, handler near jetstream_api.go:3863) with a JSON body lacking the \"group\" field or containing an empty string; the check `req.Group == _EMPTY_` fires before group-name validation.","commonSituations":"Omitting the group field in hand-written JSON; struct field tags mismatched so Group never deserializes; empty config values from template/CI variable substitution producing \"\".","solutions":["Add a non-empty \"group\" field to the request JSON.","Fix JSON field tags/serialization so the group name actually populates req.Group.","Validate the group name client-side (non-empty, matches validGroupName) before sending.","Check templating/env substitution that may inject an empty group value."],"exampleFix":"// before\n{\"stream\": \"ORDERS\", \"deliver_subject\": \"out.orders\"} // missing group\n// after\n{\"stream\": \"ORDERS\", \"group\": \"workers\", \"deliver_subject\": \"out.orders\"}","handlingStrategy":"validation","validationCode":"type groupReq struct {\n    Stream string `json:\"stream\"`\n    Group  string `json:\"group\"`\n}\nfunc validateGroupReq(b []byte) error {\n    var r groupReq\n    if err := json.Unmarshal(b, &r); err != nil { return err }\n    if r.Group == \"\" { return errors.New(\"consumer group not specified\") }\n    if !regexp.MustCompile(`^[^ *>$]+$`).MatchString(r.Group) { return errors.New(\"invalid group name\") }\n    return nil\n}\n","typeGuard":null,"tryCatchPattern":"resp, err := nc.Request(subj, body, timeout)\nif err != nil { return err }\nvar apiResp JSApiResponse\njson.Unmarshal(resp.Data, &apiResp)\nif apiResp.Error != nil && apiResp.Error.Code == 400 /* JS_INVALID_JSON */ {\n    return fmt.Errorf(\"bad request: %s\", apiResp.Error.Description)\n}","preventionTips":["Always include a non-empty group field in consumer-group requests","Verify JSON struct tags match the API's expected field names","Check template/CI variables for empty substitutions","Validate group names client-side before sending"],"tags":["jetstream","validation","json","consumer-group"],"backgroundTag":"schema-validation-failed","analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}