filter does not work
Hi,
i have a difficulty to use filter. Basically i have mocked-backend.js that the codes look like this: `"use strict";
const MOCK_DB_NAME = "mocked-db.json"; const PORT = 3001;
let jsonServer = require('json-server'); let bodyParser = require('body-parser'); let server = jsonServer.create(); let router = jsonServer.router(MOCK_DB_NAME); let middlewares = jsonServer.defaults();
// Set default middlewares (logger, static, cors and no-cache) server.use(middlewares); server.use(bodyParser.json());
// require('./mocked-api-routes')(server);
// Use default router
server.use(router)
server.listen(PORT, () => {
console.log(JSON Server is running on port ${PORT});
})`
and the mocked-db.json as follows :
{ "test-steps": [ { "test-suite-id": "1", "test-case-id": "1", "step-id": "71effb21-05f0-437c-b028-cb9a7648d3f1", "test-step-sequence": "1", "action": "Dial number", "input": "123", "wait": "1", "notes": "asdf" }, { "test-suite-id": "1", "test-case-id": "1", "step-id": "71effb21-05f0-437c-b028-cb9a7648d3f2", "test-step-sequence": "2", "action": "Dial number", "input": "123", "wait": "1", "notes": "asdf" } ] }
i try to filter the mocked-db.json using GET http://localhost:3001/test-steps?test-case-id=1 and it does not work. am i missing something?
thank you.
I am having exactly the same problem when trying to filter on a field which is a number
JSON Server automatically convert query parameters to their native type. For example, propA=true&propB=1 will be converted internally to 1 and true (instead of "1" and "true")
This way, in your db.json you can write:
{
"propA": 1,
"propB": true
}
Instead of:
{
"propA": "1",
"propB": "true"
}
To fix your issue, I would suggest updating db.json and replace strings with integers when possible.
@typicode when i am trying to modify the as you stated above, while starting json server i am getting error
Have the same problem. But in my case it doesn't work with string values either.
db.json
tickets: { "0": { "ID": "INC012345103", "AssignedUser": null, "Caption": "High CPU", "Description": null, "Priority": "1", "Project": "Project1", "Status": null, "Team": "blah blah blah", "LastCallLevel": "0", "CallStatus": "Not required", "LastCallStatus": "4", "LastUpdatedTime": "2019-09-19 18:48:43", "CreatedTime": "2019-09-18 18:16:43" }, "1": { "ID": "INC012345104", "AssignedUser": null, "Caption": "High CPU", "Description": null, "Priority": "1", "Project": "Project2", "Status": null, "Team": "blah blah blah", "LastCallLevel": "0", "CallStatus": "Not required", "LastCallStatus": "4", "LastUpdatedTime": "2019-09-19 18:48:43", "CreatedTime": "2019-09-15 18:16:43" } }
when I'm trying "tickets?ID=INC012345103" it just returns the whole data, ignoring the condition.
any clue?
Thanks in advance
Any update on this ?
I have the same issue however it works for some endpoints and for some others not