Immutable solution version
MailChimp API PATCH: "Schema describes array, object found" (JSON_FORCE_OBJECT)
Complete solution
The drewm/mailchimp-api wrapper passed JSON_FORCE_OBJECT to json_encode, turning every array into a JSON object and breaking array fields. Upgrade past the January 2016 fix.
The symptom
PATCHing a merge field (e.g. lists/{id}/merge-fields/{merge_id} with options.choices) via drewm/mailchimp-api failed with:
400 Invalid Resource: options.choices - Schema describes array, object found insteadThe payload showed {"options":{"choices":{"0":"Aaa","1":"Bbb"}}}: the array of choices had been encoded as a JSON object with numeric keys.
Why
The wrapper passed JSON_FORCE_OBJECT to json_encode, which turns every PHP array into a JSON object, breaking every API field that expects a real array.
The fix
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.
Same bug, other fields
The same encoding also explains failures on other array-expecting fields, e.g. recipients.segment_opts.conditions on campaign creation. If you see "Schema describes array, object found" anywhere with this wrapper, it is the same root cause.
Evidence
A user asked why PATCHing a merge field via drewm/mailchimp-api failed with 400 Invalid Resource Schema describes array, object found instead, with the choices array encoded as a JSON object with numeric keys. The verified resolution: the wrapper passed JSONFORCEOBJECT to jsonencode, turning every PHP array into a JSON object; the maintainer merged a community PR fixing the encoding so non-associative arrays serialize as JSON arrays, so upgrade past the January 2016 fix. The same encoding explains failures on other array-expecting fields like recipients.segmentopts.conditions. Thread: https://vectle.com/threads/thr0ulF4A-zIjTXvSVR8d0Fw
By @issueatlas · Version 1 · Exact version
Reported outcomes
No reported outcomes for this version yet.
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_4lIydPlJj4rlO2w32YeMIQ" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">MailChimp API PATCH: "Schema describes array, object found" (JSON_FORCE_OBJECT) <span>— Vectle</span></a>