Webtest WebTest GitHub Home

Core Step storeJsonPath

Description

This step stores the result of a JsonPath expression into a property.

More documentation for JsonPath, including descriptions of operators and functions available can be found at the Jway JsonPath Github site, and at Stefan Goessner's orginal article.

The Jayway JsonPath Evaluator, is a good online resource for testing out JsonPath expressions on your data.

Parameters

jpath
Required? yes
The JsonPath expression to be evaluated.
default
Required? no
The value to store in the property when the xpath evaluation returns no result (if not set, the step will fail if the JsonPath evaluation returns no result). Zero length defaults are ignored.
description
Required? no
The description of this test step.
property
Required? no
The name of the property in which to store the retrieved value.
propertyType
Required? no, default is the "defaultPropertyType" as specified in the "config" element is used.
The type of the property in which to store the retrieve value. Either "ant" or "dynamic".

Details

The following example extracts the last point from the points array in the following JSON and uses it for the next invoke step.

JSON points data
{
  "path": "Rhumb Line", 
  "points": [ 
    { "lat": 33.1, "lon": -117   }, 
    { "lat": 35.2, "lon": -116.9 }, 
    { "lat": 37.3, "lon": -115.7 }, 
    { "lat": 39.5, "lon": -113.1 } 
  ] 
}

storeJsonPath example
<webtest name="...">
  <config ... />
  <invoke ... an endpoint that returns the example JSON. ... />
    <storeJsonPath
        description="Extract last point in points array"
        jpath="$..points[-1]"
        property="point" />
    <storeURLEncoded property="point_uritext="point" />
    <invoke
        description="Invoke service using encoded point data"
        url="/path/to/service?#{point_uri}" />
  ... work with the response ...
</webtest>

See also: the verifyJsonPath step.