Previewing JSON paths

Previewing JSON paths in the API Test Editor

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.

14721472

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

📘

JSON basics

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:

  1. Create a new request.
  2. Click on the Send button. The response body will appear in the Results section.
  3. Click on the Assertions or Variables tab in the Validation and variable assignment panel.
  4. Write the JSON body path using dot notation and square brackets as needed to access nested objects and array values.
982982

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:

{
  "data": {
    "id": 7,
    "email": "[email protected]",
    "first_name": "John",
    "last_name": "Smith",
    "image": "https://example.com/7/image.jpg"
  }
}

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.

14401440

This JSON path does not match a value in the response body.

If you updated the JSON path to data.first_name or data.last_name, the API Test Editor would show a preview would update to a value from the JSON response body.