JSON Data Source

Applies to ReadyAPI 3.57, last modified on December 19, 2024

The JSON data source parses the input JSON expression by using JSONPath and populates the specified properties with the parsed values.

In this topic, we focus on how to configure the JSON data source. We assume you are already familiar with data-driven testing and how to configure a data-driven loop. Otherwise, please read Basic Concepts of Data-Driven Testing, or complete some of our tutorials before you continue.

You can use data sources of the JSON type in the Data Source test step in functional tests. They are not available in virtual services.

Configuration

The JSON data source

Click the image to enlarge it.

Source Step

Specifies a test step that contains the JSON property to read from. For example, another data source or REST Request test step.

Source Property

Specifies the property that contains JSON data.

Row Path

The JSONPath expression that returns an array element. The data source will iterate through the elements of this array and obtain the data. You can specify the expression manually or click Declare icon and select the desired element with the Select Row Path dialog. See an example below.

Column Paths

JSONPath expressions that return the desired property values. ReadyAPI applies these expressions to the JSON structure returned by the JSONPath expression specified in the Row Path.

The data source assigns data to the properties in the order they are listed in the Properties panel.

Make sure the number of properties is the same as the number of JSONPath expressions.

To add a new expression, click Add.

To change the selected expression manually, click Edit. Also, you can click Declare icon and select the desired element with the Select Column Path dialog.

To remove the selected expression, click Remove.

To learn how to specify Column Paths, see the example below.

The following example demonstrates how to configure a JSON data source:

1. Specify the source property

In the Source Step drop-down list, specify a test step whose property contains JSON data. Specify this property in the Source Property drop down list.

For example, you can specify a REST Request test step, the response to which contains JSON data:

2. Select data to iterate through

In the Row Path, specify the JSONPath expression that returns an array object with the desired data.

Assume you have the following JSON data:

JSON

{
   "store" : {
      "book" : [
         {
            "category" : "reference",
            "author" : "Nigel Rees",
            "title" : "Sayings of the Century",
            "price" : {
               "usd" : 8.95,
               "euro" : 8.95,
               "pound" : 7.95
            }
         },
         {
            "category" : "fiction",
            "author" : "Evelyn Waugh",
            "title" : "Sword of Honour",
            "price" : {
               "usd" : 12.99,
               "euro" : 12.99,
               "pound" : 11.99
            }
         },
         {
            "category" : "fiction",
            "author" : "Herman Melville",
            "title" : "Moby Dick",
            "isbn" : "0-553-21311-3",
            "price" : {
               "usd" : 8.99,
               "euro" : 8.99,
               "pound" : 7.99
            }
         },
         {
            "category" : "fiction",
            "author" : "J. R. R. Tolkien",
            "title" : "The Lord of the Rings",
            "isbn" : "0-395-19395-8",
            "price" : {
               "usd" : 22.99,
               "euro" : 22.99,
               "pound" : 20.99
            }
         }
      ],
      "bicycle" : {
         "color" : "red",
         "price" : {
            "usd" : 19.95,
            "euro" : 19.95,
            "pound" : 17.95
         }
      }
   }
}

To get a list of books, specify the following JSONPath expression:

$['store']['book']

You can specify the expression manually, or click Declare icon and select the needed element by using the Select Row Path dialog:

Configuring JSON data source: Specify Row Path

Click the image to enlarge it.

3. Specify properties to obtain

  1. Click to add a new property.

    ReadyAPI will add a new column path to the list.

  2. If the name of the added property is the same as the name of the desired JSON object in the returned array, most likely, there is no need to customize the added JSONPath. Otherwise, perform the following steps to modify the JSONPath:

    1. Select the added column path in the list.

    2. Specify the JSONPath expression that returns the desired property. Note that ReadyAPI will apply this expression to the object returned by the Row Path JSONPath expression. For example, to get the price/usd property from the JSON data above, specify the following JSONPath expression:

      ['price']['usd']

      To specify the JSONPath expression, click Declare icon to specify the expression by using the Select Column Path dialog:

      Configuring JSON data source: Specify Column Path

      Click the image to enlarge it.

      You can also click Edit and specify the expression manually.

  3. Repeat the first two steps to add other properties.

  4. Click to test the data source:

    Configuring JSON data source: Run data source

    Click the image to enlarge it.

See Also

Data Source Test Step
Data Source Loop Test Step
Groovy Data Source
Data Source Types

Highlight search results