I was trying to use _where for simple equality filtering and noticed a difference compared to standard query params.
Steps to reproduce
Minimal db.json:
{
"posts": [
{ "id": "1", "title": "foo" }
]
}
Start the server:
Compare these requests:
curl "http://localhost:3000/posts?title=foo"
curl "http://localhost:3000/posts?_where=%7B%22title%22%3A%22foo%22%7D"
curl "http://localhost:3000/posts?_where=%7B%22title%22%3A%7B%22eq%22%3A%22foo%22%7D%7D"
Actual behavior
title=foo returns the expected post:
[
{
"id": "1",
"title": "foo"
}
]
_where={"title":"foo"} returns an empty array:
_where={"title":{"eq":"foo"}} returns the expected post:
[
{
"id": "1",
"title": "foo"
}
]
Expected behavior
I initially expected _where={"title":"foo"} to behave like a simple equality filter, similar to title=foo.
If this is not intended, it might be helpful to document that _where requires operator objects, for example:
{ "title": { "eq": "foo" } }
Why this is confusing
For standard query params, title=foo works as an equality filter. Since _where accepts a JSON object, I assumed { "title": "foo" } would be the equivalent form.
The current behavior silently returns no results, so it's not immediately clear whether the query is incorrect or just not matching anything.
Environment
- json-server version: 1.0.0-beta.15
- node version: v24.12.0
- OS: Windows
- Tested with: curl.exe
I was trying to use
_wherefor simple equality filtering and noticed a difference compared to standard query params.Steps to reproduce
Minimal
db.json:{ "posts": [ { "id": "1", "title": "foo" } ] }Start the server:
Compare these requests:
Actual behavior
title=fooreturns the expected post:[ { "id": "1", "title": "foo" } ]_where={"title":"foo"}returns an empty array:_where={"title":{"eq":"foo"}}returns the expected post:[ { "id": "1", "title": "foo" } ]Expected behavior
I initially expected
_where={"title":"foo"}to behave like a simple equality filter, similar totitle=foo.If this is not intended, it might be helpful to document that
_whererequires operator objects, for example:{ "title": { "eq": "foo" } }Why this is confusing
For standard query params,
title=fooworks as an equality filter. Since_whereaccepts a JSON object, I assumed{ "title": "foo" }would be the equivalent form.The current behavior silently returns no results, so it's not immediately clear whether the query is incorrect or just not matching anything.
Environment