Answer the question
In order to leave comments, you need to log in
JSON SERVER - How to send a request to filter on multiple keys?
Good evening, I am developing a small application and for testing I use Fake REST API in the form of JSON Server.
https://github.com/typicode/json-server
I have a json in this format and I want to filter to find all items that match either by name or by author.
{
"packs": [
{ "id": 1,
"name": "Смешанный by Matt(1)",
"author": "Matt",
"imageUrl": "",
"packUrl": "",
"date": "2017-12-04 00:00:00",
"difficulty": 5,
"category": "Смешанные",
"likes": 214,
"size": 21851793,
"commentId": 37
},
{
"id": 2,
"name": "Название пакета",
"author": "Автор",
"imageUrl": "",
"packUrl": "",
"date": "2016-12-04 00:00:00",
"difficulty": 8,
"category": "Общие вопросы",
"likes": 2,
"size": 2185173,
"commentId": 34
},
]
}
Answer the question
In order to leave comments, you need to log in
What is the difficulty, the example from the documentation does not work?
Filter
Use . to access deep properties
GET /posts?title=json-server&author=typicode
GET /posts?id=1&id=2
result['packs'].filter((el)=>{return el.name == 'Название пакета' || el.author == 'Matt'})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question