diff --git a/github/rules.go b/github/rules.go index 1efb1783f92..f7ab4b613c9 100644 --- a/github/rules.go +++ b/github/rules.go @@ -573,9 +573,7 @@ type repositoryRulesetRuleWrapper struct { // MarshalJSON is a custom JSON marshaler for RulesetRules. func (r *RepositoryRulesetRules) MarshalJSON() ([]byte, error) { - // The RepositoryRulesetRules type marshals to between 1 and 22 rules. - // If new rules are added to RepositoryRulesetRules the capacity below needs increasing - rawRules := make([]json.RawMessage, 0, 22) + var rawRules []json.RawMessage if r.Creation != nil { bytes, err := marshalRepositoryRulesetRule(RulesetRuleTypeCreation, r.Creation) @@ -793,6 +791,10 @@ func (r *RepositoryRulesetRules) MarshalJSON() ([]byte, error) { rawRules = append(rawRules, json.RawMessage(bytes)) } + if len(rawRules) == 0 { + return []byte("[]"), nil + } + return json.Marshal(rawRules) }