{"record":{"id":"5e394cf42833dbaf","repo":"JuliusBrussee/caveman","slug":"cachebench-json-root-must-be-object","errorCode":null,"errorMessage":"cachebench: JSON root must be object","messagePattern":"cachebench: JSON root must be object","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cacheengine/cachebench/strictjson.go","lineNumber":45,"sourceCode":"\tif err := validateUniqueJSONValue(decoder, true, 0); err != nil {\n\t\treturn false\n\t}\n\t_, err := decoder.Token()\n\treturn errors.Is(err, io.EOF)\n}\n\nfunc validateUniqueJSONValue(decoder *json.Decoder, root bool, depth int) error {\n\tif depth > 512 {\n\t\treturn errors.New(\"cachebench: JSON nesting limit exceeded\")\n\t}\n\ttoken, err := decoder.Token()\n\tif err != nil {\n\t\treturn err\n\t}\n\tdelimiter, composite := token.(json.Delim)\n\tif !composite {\n\t\tif root {\n\t\t\treturn errors.New(\"cachebench: JSON root must be object\")\n\t\t}\n\t\treturn nil\n\t}\n\tswitch delimiter {\n\tcase '{':\n\t\tseen := map[string]bool{}\n\t\tfor decoder.More() {\n\t\t\tkeyToken, err := decoder.Token()\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t\tkey, ok := keyToken.(string)\n\t\t\tif !ok || seen[key] {\n\t\t\t\treturn errors.New(\"cachebench: duplicate or invalid object key\")\n\t\t\t}\n\t\t\tseen[key] = true\n\t\t\tif err := validateUniqueJSONValue(decoder, false, depth+1); err != nil {\n\t\t\t\treturn err","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/766dce6b1394ebb56a3090748d5a0240a5aefb36/cacheengine/cachebench/strictjson.go#L27-L63","documentation":"While validating unique-key JSON, the decoder's first token at (or inside) the document was a non-composite scalar where an object was required — most commonly the document root itself is a bare string/number/boolean instead of a JSON object. Replay bodies must be top-level objects.","triggerScenarios":"Thrown at cacheengine/cachebench/strictjson.go:45 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Wrap the payload in a top-level JSON object (e.g. {\"data\": ...})","Emit the request body with an encoder that always produces an object root"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"766dce6b1394ebb56a3090748d5a0240a5aefb36","analyzedAt":"2026-08-18T03:14:35.516Z","contentChangedAt":"2026-08-18T03:14:35.516Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}