hyperledger/fabric · error

non-empty JSON chaincode parameters must contain the followi

Error message

non-empty JSON chaincode parameters must contain the following keys: 'Args' or 'Function' and 'Args'

What it means

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.

Source

Thrown at internal/peer/chaincode/common.go:303

	// Type checking is done later when the JSON is actually unmarshaled
	// into a pb.ChaincodeInput. To better understand what's going
	// on here with JSON parsing see http://blog.golang.org/json-and-go -
	// Generic JSON with interface{}
	if chaincodeCtorJSON != "{}" {
		var f any
		err := json.Unmarshal([]byte(chaincodeCtorJSON), &f)
		if err != nil {
			return errors.Wrap(err, "chaincode argument error")
		}
		m := f.(map[string]any)
		sm := make(map[string]any)
		for k := range m {
			sm[strings.ToLower(k)] = m[k]
		}
		_, argsPresent := sm["args"]
		_, funcPresent := sm["function"]
		if !argsPresent || (len(m) == 2 && !funcPresent) || len(m) > 2 {
			return errors.New("non-empty JSON chaincode parameters must contain the following keys: 'Args' or 'Function' and 'Args'")
		}
	} else {
		return errors.New("empty JSON chaincode parameters must contain the following keys: 'Args' or 'Function' and 'Args'")
	}

	return nil
}

func validatePeerConnectionParameters(cmdName string) error {
	if connectionProfile != common.UndefinedParamValue {
		networkConfig, err := common.GetConfig(connectionProfile)
		if err != nil {
			return err
		}
		if len(networkConfig.Channels[channelID].Peers) != 0 {
			peerAddresses = []string{}
			tlsRootCertFiles = []string{}
			for peer, peerChannelConfig := range networkConfig.Channels[channelID].Peers {

View on GitHub (pinned to 2736b63f8f)

Solutions

  1. Use the new schema: --ctor '{"Args":["Init","a","1","b","2"]}'
  2. Or use the old schema with exactly two keys: --ctor '{"Function":"Init","Args":["a","1","b","2"]}'
  3. Remove any extra keys from the ctor JSON so it has exactly 1 or 2 valid keys
  4. Validate the JSON with jq before passing it (echo '<ctor>' | jq 'keys')

Example fix

// before
peer chaincode invoke -C mychannel -n mycc --ctor '{"Function":"Init"}'
// after
peer chaincode invoke -C mychannel -n mycc --ctor '{"Function":"Init","Args":["a","1","b","2"]}'
Defensive patterns

Strategy: validation

Validate before calling

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; };

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04). Data as JSON: /api/errors/d590c64f510360f4. Report an issue: GitHub.