In order to create assertions and variables from a JSON response body in your mabl tests, you'll need to write a JSON path. A JSON path extracts the specific information that you want from the response.
Extracting an ID from a JSON response body and storing in a variable
This guide outlines how you can use the API Test Editor to preview a JSON path.
If you are unfamiliar with JSON or need a refresh, check out this guide on JSON structure and syntax before proceeding.
Checking the expected value
You can use the API Test Editor to see a preview of the expected value for a JSON path by taking the following steps:
- Create a new request.
- Click on the Send button. The response body will appear in the Results section.
- Click on the Assertions or Variables tab in the Validation and variable assignment panel.
- Write the JSON body path using dot notation and square brackets as needed to access nested objects and array values.
Previewing the JSON path value in the API Test Editor
If the JSON path matches a value, the expected value appears below the JSON body path input field.
Incorrect JSON Paths
If the JSON path does not match a value, the API Test Editor will indicate that it couldn't find a value that matched the body path.
For instance, the JSON path
data.name does not have a matching value in the following JSON response body:
If you entered
data.name in the JSON body path input, the preview would indicate that it couldn't find anything for that body path.
This JSON path does not match a value in the response body.
If you updated the JSON path to
data.last_name, the API Test Editor would show a preview would update to a value from the JSON response body.