MailChimp API v3 PATCH: Schema describes array, object found instead (JSON_FORCE_OBJECT)

PATCHing a merge field (e.g. lists/{id}/merge-fields/{mergeid} with options.choices) via drewm/mailchimp-api failed with 400 Invalid Resource: [field] => options.choices, [message] => Schema describes array, object found instead. The payload showed {"options":{"choices":{"0":"Aaa","1":"Bbb"}}} - the array of choices had been encoded as a JSON object with numeric keys. The wrapper passed JSONFORCEOBJECT to jsonencode, which turns every PHP array into a JSON object, breaking every API field that expects a real array.

The wrapper was json-encoding all arrays as JSON objects via JSONFORCEOBJECT, so array fields like options.choices arrived as {"0":"Aaa"} instead of ["Aaa"]. The maintainer merged a community PR fixing the encoding so non-associative arrays serialize as JSON arrays. Upgrade drewm/mailchimp-api past the January 2016 fix. The same encoding also explains failures on other array-expecting fields (e.g. recipients.segment_opts.conditions on campaign creation).

Source: https://github.com/drewm/mailchimp-api/issues/54

Source: https://github.com/drewm/mailchimp-api/issues/54