admin管理员组

文章数量:1406949

I'm trying to make a get request to json-server to get in a nested object. But it is returning an empty response instead of the object key data.

I have gone through the documentation and there is nothing specific to the db structure that I have.

I want to filter the model array but not getting the model data.

my db.json file is

  {
      "data": {
          "model": 
            [
               {
                  "name": "BERLINGO",
                  "manufacturerName": "CITREON",
                  "id": 1
              },
              {
                  "name": "C3",
                  "manufacturerName": "CITREON",
                  "id": 2
              }
          ]
      }
  }

For GET /data , I'm getting the following response.

{
  "model": [
    {
      "name": "BERLINGO",
      "manufacturerName": "CITREON",
      "id": 1
    },
    {
      "name": "C3",
      "manufacturerName": "CITREON",
      "id": 2
    }
  ]
}

GET call for /data/model is giving an empty object.

{}

I'm trying to make a get request to json-server to get in a nested object. But it is returning an empty response instead of the object key data.

I have gone through the documentation and there is nothing specific to the db structure that I have.

I want to filter the model array but not getting the model data.

my db.json file is

  {
      "data": {
          "model": 
            [
               {
                  "name": "BERLINGO",
                  "manufacturerName": "CITREON",
                  "id": 1
              },
              {
                  "name": "C3",
                  "manufacturerName": "CITREON",
                  "id": 2
              }
          ]
      }
  }

For GET /data , I'm getting the following response.

{
  "model": [
    {
      "name": "BERLINGO",
      "manufacturerName": "CITREON",
      "id": 1
    },
    {
      "name": "C3",
      "manufacturerName": "CITREON",
      "id": 2
    }
  ]
}

GET call for /data/model is giving an empty object.

{}

Share asked Jun 13, 2019 at 14:21 ExpertNoobExpertNoob 1391 silver badge9 bronze badges 4
  • Where is the code for the call you are making? – basic Commented Jun 13, 2019 at 14:23
  • I'm just making a GET call directly from the browser URL bar as of now to test if I'm getting the data. Eventually, I'll be doing it inside my react app with axios – ExpertNoob Commented Jun 13, 2019 at 14:24
  • Is there any log at console? – Juan Diego Lozano Commented Jun 13, 2019 at 14:32
  • @JDLozano yes, in the chrome netwrok tab, it has the 404 error, same in the json-server, i.e. the 404 error for the request /data/model – ExpertNoob Commented Jun 13, 2019 at 14:35
Add a ment  | 

1 Answer 1

Reset to default 6

Unfortunately, json-server does not support such "nested value" syntax. You can GET /data, but cannot GET /data/model or GET /data.model. All you can do is fetching the whole /data object and access model field of it.

This is already discussed in json-server's GitHub Repo, and according to an older discussion, it seems the owner of json-server (@typicode) does not intend to make this support.

本文标签: javascriptNot able to GET object key data in JSONSERVERStack Overflow