{"record":{"id":"d590c64f510360f4","repo":"hyperledger/fabric","slug":"non-empty-json-chaincode-parameters-must-contain-t","errorCode":null,"errorMessage":"non-empty JSON chaincode parameters must contain the following keys: 'Args' or 'Function' and 'Args'","messagePattern":"non-empty JSON chaincode parameters must contain the following keys: 'Args' or 'Function' and 'Args'","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/peer/chaincode/common.go","lineNumber":303,"sourceCode":"\t// Type checking is done later when the JSON is actually unmarshaled\n\t// into a pb.ChaincodeInput. To better understand what's going\n\t// on here with JSON parsing see http://blog.golang.org/json-and-go -\n\t// Generic JSON with interface{}\n\tif chaincodeCtorJSON != \"{}\" {\n\t\tvar f any\n\t\terr := json.Unmarshal([]byte(chaincodeCtorJSON), &f)\n\t\tif err != nil {\n\t\t\treturn errors.Wrap(err, \"chaincode argument error\")\n\t\t}\n\t\tm := f.(map[string]any)\n\t\tsm := make(map[string]any)\n\t\tfor k := range m {\n\t\t\tsm[strings.ToLower(k)] = m[k]\n\t\t}\n\t\t_, argsPresent := sm[\"args\"]\n\t\t_, funcPresent := sm[\"function\"]\n\t\tif !argsPresent || (len(m) == 2 && !funcPresent) || len(m) > 2 {\n\t\t\treturn errors.New(\"non-empty JSON chaincode parameters must contain the following keys: 'Args' or 'Function' and 'Args'\")\n\t\t}\n\t} else {\n\t\treturn errors.New(\"empty JSON chaincode parameters must contain the following keys: 'Args' or 'Function' and 'Args'\")\n\t}\n\n\treturn nil\n}\n\nfunc validatePeerConnectionParameters(cmdName string) error {\n\tif connectionProfile != common.UndefinedParamValue {\n\t\tnetworkConfig, err := common.GetConfig(connectionProfile)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tif len(networkConfig.Channels[channelID].Peers) != 0 {\n\t\t\tpeerAddresses = []string{}\n\t\t\ttlsRootCertFiles = []string{}\n\t\t\tfor peer, peerChannelConfig := range networkConfig.Channels[channelID].Peers {","sourceCodeStart":285,"sourceCodeEnd":321,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/internal/peer/chaincode/common.go#L285-L321","documentation":"This error is thrown by checkChaincodeCmdParams when the --ctor (chaincode constructor) JSON string is non-empty but its keys don't match the accepted schemas. The peer CLI only accepts either {\"Args\":[...]} (new schema) or {\"Function\":\"fn\",\"Args\":[...]} (old schema), checked case-insensitively after lowercasing keys. Any other combination of keys or key count results in this error.","triggerScenarios":"Running a peer chaincode invoke/query/install command with a non-empty --ctor JSON that: has no 'Args' key (e.g. '{\"Function\":\"init\"}'), has 2 keys where the second isn't 'Function' (e.g. '{\"args\":[],\"foo\":1}'), or has more than 2 keys.","commonSituations":"Typos in the ctor JSON (extra keys like 'Type' or 'Transient' wrongly placed inside ctor), passing a JSON object with only a Function and no Args, copy-pasting examples with outdated or extended schemas, quoting issues that mangle the JSON into unexpected keys.","solutions":["Use the new schema: --ctor '{\"Args\":[\"Init\",\"a\",\"1\",\"b\",\"2\"]}'","Or use the old schema with exactly two keys: --ctor '{\"Function\":\"Init\",\"Args\":[\"a\",\"1\",\"b\",\"2\"]}'","Remove any extra keys from the ctor JSON so it has exactly 1 or 2 valid keys","Validate the JSON with jq before passing it (echo '<ctor>' | jq 'keys')"],"exampleFix":"// before\npeer chaincode invoke -C mychannel -n mycc --ctor '{\"Function\":\"Init\"}'\n// after\npeer chaincode invoke -C mychannel -n mycc --ctor '{\"Function\":\"Init\",\"Args\":[\"a\",\"1\",\"b\",\"2\"]}'","handlingStrategy":"validation","validationCode":"ctor='{\"Function\":\"Init\",\"Args\":[\"a\",\"1\"]}'; echo \"$ctor\" | jq -e '((keys_unsorted | map(ascii_downcase)) == [\"args\"]) or ((keys_unsorted | map(ascii_downcase) | sort) == [\"args\",\"function\"])' >/dev/null || { echo 'invalid ctor schema'; exit 1; };","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always use {\"Args\":[...]} or {\"Function\":\"f\",\"Args\":[...]} and nothing else in --ctor","Put transient data in --transient, never inside ctor JSON","Pipe ctor JSON through jq to check keys before running the command","Remember keys are matched case-insensitively but count of keys still matters"],"tags":["hyperledger-fabric","chaincode","cli","json-validation"],"backgroundTag":"invalid-json-constructor-args","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"}