{"record":{"id":"9cce864aa02b401c","repo":"hyperledger/fabric","slug":"failed-to-unmarshal-json-v-into-dataformatinfo","errorCode":null,"errorMessage":"failed to unmarshal json [%#v] into dataformatInfo","messagePattern":"failed to unmarshal json \\[%#v\\] into dataformatInfo","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/ledger/kvledger/txmgmt/statedb/statecouchdb/couchdoc_conv.go","lineNumber":271,"sourceCode":"\nfunc encodeDataformatInfo(dataFormatVersion string) (*couchDoc, error) {\n\tvar err error\n\tdataformatInfo := &dataformatInfo{\n\t\tVersion: dataFormatVersion,\n\t}\n\tdataformatInfoJSON, err := json.Marshal(dataformatInfo)\n\tif err != nil {\n\t\terr = errors.Wrapf(err, \"failed to marshal dataformatInfo [%#v]\", dataformatInfo)\n\t\tlogger.Errorf(\"%+v\", err)\n\t\treturn nil, err\n\t}\n\treturn &couchDoc{jsonValue: dataformatInfoJSON, attachments: nil}, nil\n}\n\nfunc decodeDataformatInfo(couchDoc *couchDoc) (string, error) {\n\tdataformatInfo := &dataformatInfo{}\n\tif err := json.Unmarshal(couchDoc.jsonValue, dataformatInfo); err != nil {\n\t\terr = errors.Wrapf(err, \"failed to unmarshal json [%#v] into dataformatInfo\", couchDoc.jsonValue)\n\t\tlogger.Errorf(\"%+v\", err)\n\t\treturn \"\", err\n\t}\n\treturn dataformatInfo.Version, nil\n}\n\nfunc validateValue(value []byte) error {\n\tisJSON, jsonVal := tryCastingToJSON(value)\n\tif !isJSON {\n\t\treturn nil\n\t}\n\treturn jsonVal.checkReservedFieldsNotPresent()\n}\n\nfunc validateKey(key string) error {\n\tif !utf8.ValidString(key) {\n\t\treturn errors.Errorf(\"invalid key [%x], must be a UTF-8 string\", key)\n\t}","sourceCodeStart":253,"sourceCodeEnd":289,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/ledger/kvledger/txmgmt/statedb/statecouchdb/couchdoc_conv.go#L253-L289","documentation":"decodeDataformatInfo unmarshals the stored dataformatInfo JSON document to determine which data format version the state database uses. If the bytes cannot be unmarshaled, the error is wrapped as 'failed to unmarshal json [%#v] into dataformatInfo' and readDataformatVersion fails, blocking ledger open.","triggerScenarios":"readDataformatVersion reads the dataformatVersion document from CouchDB and its jsonValue cannot be unmarshaled into dataformatInfo (corrupt or wrong-typed fields).","commonSituations":"Manual edits to the internal dataformat document, partial backups/restores, external tools writing into the ledger database, or version-incompatible databases.","solutions":["Inspect the dataformat document in CouchDB; fix or restore valid JSON like {\"Version\":\"2.0\"}","Restore the state database from a good backup taken with the same Fabric version","If the database is unrecoverable, drop the database and let the peer rebuild it (data must be re-synced)"],"exampleFix":"// before (corrupt doc)\n{\"Version\": {\"bad\": true}}\n// after\n{\"Version\": \"2.0\"}","handlingStrategy":"try-catch","validationCode":"func validDataformatJSON(b []byte) bool {\n    var d struct{ Version string }\n    return json.Unmarshal(b, &d) == nil && d.Version != \"\"\n}","typeGuard":null,"tryCatchPattern":"v, err := decodeDataformatInfo(doc)\nif err != nil {\n    return \"\", fmt.Errorf(\"dataformat document corrupt; restore or rebuild state DB: %w\", err)\n}","preventionTips":["Protect internal dataformat documents from manual edits","Use backups from the same Fabric data-format version","Restrict external tools from writing into ledger databases"],"tags":["json","unmarshalling","data-format","fabric-ledger","couchdb"],"backgroundTag":"json-unmarshalling-failed","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"}