{"record":{"id":"9312a00b1b4bf33c","repo":"hyperledger/fabric","slug":"invalid-input-json-contains-duplicate-record-for","errorCode":null,"errorMessage":"invalid input json. Contains duplicate record for  {\"namespace\":\"%s\",\"key\":\"%s\"}. Aborting identifytxs","messagePattern":"invalid input json\\. Contains duplicate record for  (.+?)\\. Aborting identifytxs","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/ledgerutil/identifytxs/identifytxs.go","lineNumber":200,"sourceCode":"\t\t\treturn nil, errors.Errorf(\"invalid input json. Each record entry must contain both \" +\n\t\t\t\t\"a \\\"namespace\\\" and a \\\"key\\\" field. Aborting identifytxs\")\n\t\t}\n\t\t// Check for hashed data\n\t\tvar ns, coll string\n\t\tif r.Hashed {\n\t\t\tns, coll, err = decodeHashedNs(r.Namespace)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\t\t} else {\n\t\t\tns = r.Namespace\n\t\t}\n\t\t// Record to compKey\n\t\tck := compKey{namespace: ns, collection: coll, key: r.Key}\n\t\t// Check for duplicate entry\n\t\t_, exists := inputKeyMap[ck]\n\t\tif exists {\n\t\t\treturn nil, errors.Errorf(\"invalid input json. Contains duplicate record for \"+\n\t\t\t\t\" {\\\"namespace\\\":\\\"%s\\\",\\\"key\\\":\\\"%s\\\"}. Aborting identifytxs\", r.Namespace, r.Key)\n\t\t}\n\t\t// New entry, add entry and height\n\t\tblockNum, txNum := r.GetLaterHeight()\n\t\t// Only namespace and key were provided, record doesn't contain height. Set to \"infinite\" height to iterate entire block store.\n\t\tif blockNum == 0 && txNum == 0 {\n\t\t\tblockNum = math.MaxUint64\n\t\t\ttxNum = math.MaxUint64\n\t\t}\n\t\t// Check for max height\n\t\tif blockNum > maxBlock || (blockNum == maxBlock && txNum > maxTx) {\n\t\t\tmaxBlock = blockNum\n\t\t\tmaxTx = txNum\n\t\t}\n\t\t// Create output file writer\n\t\tfilename := fmt.Sprintf(\"txlist%d.json\", i+1)\n\t\tofw, err := jsonrw.NewJSONFileWriter(filepath.Join(outputDirPath, filename))\n\t\tif err != nil {","sourceCodeStart":182,"sourceCodeEnd":218,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/internal/ledgerutil/identifytxs/identifytxs.go#L182-L218","documentation":"generateRecordsMap keys records by (namespace, collection, key); a duplicate (namespace,key) pair in the input JSON makes the map ambiguous (later-height tracking would conflict), so it returns this error naming the duplicated namespace/key and aborts IdentifyTxs.","triggerScenarios":"Running ledgerutil identifytxs with a diff record list that contains two records with the same namespace and key (collection differing may still collide when both are unhashed/empty).","commonSituations":"Manually merging or concatenating two diff JSON outputs; duplicates introduced while editing the file; combining records from multiple compare runs into one list.","solutions":["Remove duplicate entries with the same namespace/key from the JSON, keeping the one with the latest height if applicable","Regenerate a single diff record list from one compare run instead of merging files","Preprocess with a script that dedupes on (namespace, collection, key) before invoking identifytxs"],"exampleFix":"// before\n[{\"namespace\":\"ns\",\"key\":\"k1\"},{\"namespace\":\"ns\",\"key\":\"k1\"}]\n// after\n[{\"namespace\":\"ns\",\"key\":\"k1\"}]","handlingStrategy":"validation","validationCode":"// Go: dedupe records on namespace/collection/key before calling IdentifyTxs\nseen := map[string]bool{}\nvar out []models.DiffRecord\nfor _, r := range records.DiffRecords {\n    k := r.Namespace + \"|\" + r.Key\n    if seen[k] { continue }\n    seen[k] = true\n    out = append(out, r)\n}","typeGuard":null,"tryCatchPattern":"if _, _, err := ledgerutil.IdentifyTxs(recPath, outDir); err != nil {\n    if strings.Contains(err.Error(), \"duplicate record\") {\n        return fmt.Errorf(\"dedupe namespace/key pairs in the diff JSON: %w\", err)\n    }\n    return err\n}","preventionTips":["Never concatenate diff JSONs from multiple compare runs","Preprocess inputs to dedupe on (namespace, collection, key)","Use one authoritative compare output per identifytxs run"],"tags":["hyperledger-fabric","ledgerutil","json-input","duplicate-records"],"backgroundTag":"duplicate-json-record","analyzedSha":"2736b63f8fd5932511d56fe68b7039d15977f7f6","analyzedAt":"2026-09-04T08:52:36.465Z","contentChangedAt":"2026-09-04T08:52:36.465Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}