How can I validate the structure of HTTP Response in JavaScript? [closed]

How can I validate the structure of HTTP Reesponse in JavaScript?

Right now, the API is returning in the following structure:

{
  id:1,
  name: 'Bob',
  books: [1,2,3]
}

On successful API call from client side: I expect the response body to respect the above structure. How can I validate that the response indeed is returned in the agreed upon json format shown above. Values of each properties is irrelevant here.

For instance the following are all invalid:

  1. Invalid

    {
      id:1,
      full_name: 'Bob',
      books: [1,2,3]
    }
    
  2. Invalid

    {
      id:1,
      name: 'Bob'
    }
    
  3. Invalid

    {
      id:1,
      name: 'Bob'
    }
    

But the following are valid:

  1. Valid

    {
      id:1,
      name: 'Bob',
      books: [1,2,3]
    }
    
  2. Valid

    {
      id:1,
      name: null,
      books: []
    }
    
  3. Valid

    {
      id:null,
      name: null,
      books: null
    }