Skip to content

Unexpected behavior with plain equality in _where #1757

@Omar-Tnt04

Description

@Omar-Tnt04

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:

npx json-server db.json

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions