[wp-trac] [WordPress Trac] #64926: REST API: GET requests fail object/array schema validation when params are JSON-serialized strings
WordPress Trac
noreply at wordpress.org
Wed Mar 25 01:13:04 UTC 2026
#64926: REST API: GET requests fail object/array schema validation when params are
JSON-serialized strings
-------------------------------------+-------------------------------------
Reporter: dsmy | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: REST API | Version: trunk
Severity: normal | Resolution:
Keywords: needs-patch reporter- | Focuses: javascript, rest-api,
feedback | php-compatibility
-------------------------------------+-------------------------------------
Comment (by dsmy):
Bracket notation (?user[name]=Bob&user[pet]=cat) does work server side,
and you're right that PHP has a native convention for it. The problem is
on the client side.
From what I've seen URLSearchParams doesn't support bracket notation
natively. Constructing it manually for deeply nested objects is tedious,
error prone, and there's no standard JavaScript API that bridges the two.
GET and POST handle structured params through different code paths, and
only POST has the JSON decode step.
But "use bracket notation and construct it manually in JavaScript" is not
a documented pattern, not what developers will naturally do, and not what
the REST API's own tooling produces. The JSON.stringify() path is broken
where it should reasonably work.
Hope that gives a better insight!
Replying to [comment:3 westonruter]:
> Thank you for the ticket.
>
> > When a REST endpoint declares a parameter with "type": "object" or
"type": "array", GET requests cannot pass that parameter correctly.
URLSearchParams has no native way to encode nested structures, so the only
option is JSON.stringify(), producing ?input={"post_id":123}.
>
> While `URLSearchParams` may not know how to encode that, doesn't PHP
have a convention for this?
>
> To pass an array as `foo`, you can do `?foo[]=1&foo[]=2&foo[]=3`.
>
> To pass an object:`?user[name]=Bob&user[pet]=cat`.
>
> Does this not work?
--
Ticket URL: <https://core.trac.wordpress.org/ticket/64926#comment:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list