For the complete documentation index, see llms.txt. This page is also available as Markdown.

JSONPath match

This is a pre-built action available under @Assertion. This Action validates whether the value extracted from the API response using a JSONPath expression matches the expected value. If the extracted value matches the expected value, the assertion passes; otherwise, it fails.

Note: An API request must be added and executed successfully before configuring or evaluating API Assertions.

Syntax

Input Value: <JSONPath expression>;<JSONPath expected value>

Note: You can generate expressions automatically using the Assertion expression builder available for the Response JSON Body. The generated expression can be used directly as the input for the JSONPath match action.

Argument
Description

<JSONPath expression>

(Required)

Specify the JSONPath expression used to extract the value from the API response.

<JSONPath expected value>

(Required)

Specify the value to compare with the extracted value.

Output Value: <Actual value(optional)>;<Keyword Status(optional)>

Argument
Description

<Actual value>

(optional)

The actual value stores the value extracted from the API response using the specified JSONPath expression.

<Keyword Status>

(optional)

The keyword status variable stores the status as True or False.

Example 1: Validating a JSON Value

In this example, we verify that a value extracted from the API response matches the expected value.

  • Action: JSONPath match

  • Input Value: $.company.name;TechsNova

    • The first part ($.company.name) specifies the JSONPath expression used to extract the value from the API response.

    • The second part (TechsNova) specifies the expected value.

  • Output Value: {Actual Value};{Keyword Status}

    • The first output variable {Actual Value} stores the value extracted from the API response.

    • If the second output variable {Keyword Status} is defined, it stores the assertion result with the following possible values:

      • True: If the extracted value matches the expected value.

      • False: If the extracted value does not match the expected value.

  • Logical Explanation: The JSONPath match action evaluates the JSONPath expression ($.company.name) against the API response and extracts the value TechsNova. The extracted value is stored in the {Actual Value} variable. The action then compares the extracted value with the expected value ("TechsNova"). If both values match, {Keyword Status} stores True; otherwise, it stores False.

Example 2: Validating a Filtered JSON Value

Note: To use a filter JSON expression, you must add it manually.

In this example, we verify the employee count for the branch located in Bengaluru using a JSONPath filter.

  • Action: JSONPath match

  • Input Value: $.company.locations.branches[?(@.city=="Bengaluru")].employees;120

    • The first part ($.company.locations.branches[?(@.city=="Bengaluru")].employees) specifies the JSONPath filter expression.

      • ?() defines the filter expression.

      • @.city=="Bengaluru" filters the branch whose city is Bengaluru.

      • .employees extracts the employee count from the matching branch.

    • The second part (120) specifies the expected value.

  • Output Value: {Actual Value};{Keyword Status}

    • The first output variable {Actual Value} stores the value extracted from the API response.

    • If the second output variable {Keyword Status} is defined, it stores the assertion result with the following possible values:

      • True: If the extracted value matches the expected value.

      • False: If the extracted value does not match the expected value.

  • Logical Explanation: The JSONPath match action evaluates the filter expression against the API response and locates the branch whose city is Bengaluru. It extracts the corresponding employee count (120) and stores it in the {Actual Value} variable. The action then compares the extracted value with the expected value (120). If both values match, {Keyword Status} stores True; otherwise, it stores False.

Supported JSONPath Expressions

Symbol
Meaning
Example
Purpose
Returns

$

Root JSON

$

To reference the root of the JSON document.

Entire JSON object

.

Child property

$.company.name

To access a child property of a JSON object.

TechNova

['key']

Property with spaces/special chars

$.company[‘first name’]

To access a property whose name contains spaces or special characters.

John

[0]

Array index

$.branches[0].city

To access an element at a specific array index.

Bengaluru

[-1]

Last array element

$.branches[-1].city

To access the last element in an array.

Hyderabad

[0,1]

Multiple indices

$.branches[0,1]

To access elements at multiple specified array indices.

First & second elements

[1:3]

Array slice

$.languages[1:3]

To access a range of array elements.

Subset of array

[0:5:2]

Slice with step

$.languages[0:5:2]

To access array elements within a range using a specified step value.

Every 2nd element

[*]

Wildcard

$.branches[*].city

To access all elements in an array or all matching child properties.

All city values

.*

All child properties

$.company.*

To access all child properties of an object.

All child values

..

Recursive descent

$..city

To recursively search for a property throughout the JSON document.

Every city in JSON

[?(condition)]

Filter

$.branches[?(@.employees>100)]

To filter array elements based on one or more conditions.

Matching objects

&&

Logical AND

@.city=='A' && @.employees>100

To combine multiple conditions where all conditions must be true.

Both conditions true

||

Logical OR

@.city=='A' || @.employees>100

To combine multiple conditions where at least one condition must be true.

Either condition true

== != > < >= <=

Comparison operators

@.employees>=100

To compare values within a filter expression.

Comparison

Last updated