JSON Schema Validation

The goal of the JSON Schema Validation interceptor is to check if the body content of a request or response to some API is following the established rules of a JSON schema defined in the interceptor during its configuration.

To set up the interceptor:

  1. Go to the Flows page of an API;

  2. Access the Traffic tab;

  3. Drag the JSON Schema Validation interceptor to the request or response flow.

json schema locale

After you define where the interceptor will run, a new screen will open for the description of the JSON schema that will validate the JSON content transmitted in the call, as shown below:

json schema example

The JSON schema above validates a simple object containing the attributes firstName, lastName, and age, with the first two attributes set as mandatory (via the "required" attribute) and the age limit being described by the attribute minimum.

For further information about the JSON schema specification and how to build a validation file per your demands, access http://json-schema.org.

After establishing the definitions of your JSON schema file, click the Save button to record your changes and continue with the regular procedures of API creation (clicking the Continue button on the Flows screen). When a call is made to the API, the interceptor will be available to execute validations.

The example below represents a call to an API using the JSON Schema Validation interceptor displayed on the previous image.

json schema call example

Note that, during the call, we simulate the lack of the attribute lastName on the request body. Therefore, the validation response for the JSON schema used will always be the HTTP Status 417, followed by an object containing the result of the whole process, as displayed below.

json schema call result
Thanks for your feedback!
EDIT

Share your suggestions with us!
Click here and then [+ Submit idea]