As per the spec multiple filter values can be combined with a comma.
Multiple filter values can be combined in a comma-separated list. For example:
GET /comments?filter[post]=1,2 HTTP/1.1
What if a value itself contains a comma?
like /hotels?filter[location]=Abbey Wood, London,Manchester
where "Abbey Wood, London"
is a single location.
In the ?include
and ?fields
params, which are the only parameters that have their values strictly defined by the spec, this problem can’t happen because the member naming rules disallow field names with commas in them.
For other parameters, like ?page
, and ?filter
, the spec suggests what they should be used for, but says nothing binding/normative about their syntax, so how to handle this is up to you/each implementation. One natural way would be to percent encode any commas that appear within data values, to distinguish them from commas that are acting as delimiters.
For ?sort
, there’s an open issue: https://github.com/json-api/json-api/issues/1266
2 Likes
Yes thx, I think it’s good to urlencode commas in the filter value(s).