JSON assertion editor

The JSON assertion editor allows you to configure and run assertions against JSON response data with JSONPath. JSONPath can return a single (complex) value or a list of values.

JSON(Path) Assertion editor

JSONPath editor with expression

Writing assertions can be cumbersome if you need to work with several query languages, like SQL, JSONPath and XPath to mention some of them. APIJockey TEST supports you with a large set of predefined queries that can apply on your JSON objects. The idea is to let you query the JSON objects with a small subset of JSONPath expressions and assert these objects in various ways by configuring what you actually want to test.

A JSON assertion expects a valid JSONPath expression. You may enter you assertion here. The JSONPath assertion will be executed against the current response. In case of errors, these will be displayed in the editor.

Expected return type

When you edit a JSONPath Expression, you need to select the type of return value that you expect. We will use this information to provide an appropriate set of assertion test types:

The JSON assertion in the above screenshot selects a list of prices. Thus, the expected return type is set to list of floating values.

You have the following list of expected return types:

Expected return type and assertion Type

Return types that expect one value

The assertion will fail, if the expected return type does not equal the actual return type, e.g. expected: List of booleans, actual: single boolean.

The assertion type determines the way the assertion is verified:

Boolean value

  • true
  • false

Date with formatting

  • Date is day of run date
  • Date is not nil
  • Date is nil/null or not present
  • Date is equal expected day
  • Date has equal distance from ... based on current timestamp :
    When you expect a date to be 3 days in the past, whenever you run the testcase, you would pick the current day - 3 days. The assertion will verify if the actual day is three days before the current execution date.
  • Date is day of run date (today)
  • Date is day before run date (today)
  • Date is day after run date (today)
  • Date applies formatting

Floating point value

A Floating point is a double or float value.

  • Number is equal ...
  • Number is smaller than ...
  • Number is greater than ...
  • Number is between lower ... and upper ...
  • Number is NOT between lower ... and upper ...

Integer value

  • Number is equal ...
  • Number is smaller than ...
  • Number is greater than ...
  • Number is between lower ... and upper ...
  • Number is NOT between lower ... and upper ...
  • Number is in expected list

Text

Text is a good option, if your uncertain about the return value type, but know, there is no array being returned.

  • Text contains expected
  • Text equals expected
  • Text begins with expected
  • Text ends with expected
  • Text contains expected (case insensitive)
  • Text equals expected (case insensitive)
  • Text begins with expected (case insensitive)
  • Text ends with expected (case insensitive)
  • Text is empty
  • Text is NOT empty
  • Text has expected length
  • Text has minimum expected length
  • Text has maximum expected length

Dictionary

JSON is constructed from Arrays and Dictionaries, so assessing content of dictionaries is a common check

  • Dictionary entry exists (Dictionary contains key)
  • Dictionary entry NOT exists (Dictionary does not contain key)
  • Dictionary entry has value
  • Dictionary entry has NOT value
  • Element contains expected
  • Dictionary contains expected (case insensitive)
  • Dictionary NOT contains expected
  • Dictionary NOT contains expected (case insensitive)

List of values (Arrays)

JSONPath may return arrays, APIJockey Test makes it easy to perform validation for all of the entries

List of boolean values

  • All elements return true
  • All elements return false

List of integer values

  • All values equal expected
  • All values smaller expected
  • All values greater expected
  • All values between lower and upper range
  • All values NOT between lower and upper range
  • number (of array element) count equals expected
  • number (of array element) count smaller expected
  • number (of array element) count greater expected
  • number (of array element) count between ... and ...
  • number (of array element) count NOT between ... and ...

List of date values

  • All dates are not nil
  • All dates are nil or not present
  • All values are equal expected
  • All values are equal to relative date based on current timestamp :
    When you expect a date to be 3 days in the past, whenever you run the testcase, you would pick the current day - 3 days. The assertion will verify if the actual day is three days before the current execution date.
  • All dates are today
  • All dates are yesterday
  • All dates are tomorrow
  • All dates apply formatting

List of floating values

  • All have expected value
  • All are smaller expected
  • All are greater expected
  • number (of array element) count equals expected
  • number (of array element) count smaller expected
  • number (of array element) count greater expected
  • number (of array element) count between ... and ...
  • number (of array element) count NOT between ... and ...
  • All elements between lower and upper range
  • All elements NOT between lower and upper range

List of text values

  • All values equal expected expected
  • All values begin with expected
  • All values end with expected
  • All values contain expected
  • All values begin with expected (case insensitive)
  • All values end with expected (case insensitive)
  • All values contain expected (case insensitive)
  • number (of array element) count equals expected
  • number (of array element) count smaller expected
  • number (of array element) count greater expected

List of dictionaries

  • All dictionaries have expected key
  • None of the dictionaries have expected key
  • Element count equals expected
  • Element count smaller expected
  • Element count greater expected
  • Element count between ... and ...
  • Element count NOT between ... and ...
  • All dictionaries have expected value
  • None of the dictionaries havs expected value
  • All dictionaries contain expected value
  • None of the dictionaries contain expected value
  • All dictionaries contain expected value (case insensitive)
  • None of the dictionaries contain expected value (case insensitive)

Expected value

The expected value depends on the assertion test type and is either:

  • single expected value
  • a lower range limit and an upper range limit
  • a list of values
  • A JSON dictionary key name

Run assertion

Run assesses the current response data against the assertion test type, the expected value and the actual value. The actual JSON response is kept in memory, so you can rerun a test as often as you want and change it.