Getting JSON user data by jquery

0

I have a json that I'm running through json-server and it's at: link

Within it, it has a scope of "users", which I would like to take.

I have the following script I put together, it follows:

$.getJSON(urlParam, function (data) {
        let itens = []
        $.each( data, function (key, val) {
            itens.push( {key, val} )
        })
        return itens
})

I would like to get both a user list, which is converted to json, both a user only.

Follow my json:

{
  "alunos": [
    {
      "id": 1,
      "nome": "Thiago Cunha"
    },
    {
      "id": 2,
      "nome": "Caroline Cunha"
    },
    {
      "id": 3,
      "nome": "Thalita Cunha"
    }
  ],
  "users": [
    {
      "id": 1,
      "nome": "Thiago Cunha",
      "img": "dist/images/thiago.jpg",
      "status": true
    },
    {
      "id": 2,
      "nome": "Caroline Cunha",
      "img": "dist/images/thiago.jpg",
      "status": true
    },
    {
      "id": 3,
      "nome": "Thalita Cunha",
      "img": "dist/images/thiago.jpg",
      "status": true
    }
  ]
}

Can anyone help me please?

    
asked by anonymous 11.05.2018 / 19:38

1 answer

1

In my humble opinion you could create a different endpoint to fetch individual user registration, one for user search and one for all users. For example: url /users for all users and url /user/id (where id is the primary key or user identifier) for individual user registration.

    
11.05.2018 / 19:46