We can also use it as part of our automation test for our service.
How does it work. We have two JSON strings. One is a response that we get from a service and the other is a model of the JSON structure that we expect the service to return - the contract of the service to the clients/users. We check that the response corresponds to the model - if all the keys and structure of the model are present in the response, then it is valid.
Here is a short description of the algorithm:
Does the key from the model exist in the response:
No - response is not valid
is the value a JSON object:
Yes -> validate JSON object
is the value a JSON array:
Yes -> validate JSON arrayelse continue to next key.
The repository for the project is at GitHub and contains implementation for Objective-C, Java and Go: