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:
-
Invalid
{ id:1, full_name: 'Bob', books: [1,2,3] }
-
Invalid
{ id:1, name: 'Bob' }
-
Invalid
{ id:1, name: 'Bob' }
But the following are valid:
-
Valid
{ id:1, name: 'Bob', books: [1,2,3] }
-
Valid
{ id:1, name: null, books: [] }
-
Valid
{ id:null, name: null, books: null }