In this article, we will introduce JSONPath, which is used in JSON Extractor, and present an example of selecting an object/element based on multiple criteria with it.[1]

JSON Extractor / JSONPath

One of the advantages of XML is the availability of numerous tools to analyse, transform and selectively extract data out of XML documents. XPath is one of these powerful tools. For JSON, we have a similar tool called JSONPath.

JSONPath is the XPath for JSON. Since a JSON structure is normally anonymous, JSONPath assigns symbol $ as the root object.

Below is a side-by-side comparison of the JSONPath syntax elements with its XPath counterparts.[3]

XPath

JSONPath

Description

/

$

the root object/element

.

@

the current object/element

/

. or []

child operator

..

n/a

parent operator

//

..

recursive descent. JSONPath borrows this syntax from E4X.

*

*

wildcard. All objects/elements regardless their names.

@

n/a

attribute access. JSON structures don't have attributes.

[]

[]

subscript operator. XPath uses it to iterate over element collections and for predicates. In Javascript and JSON it is the native array operator.

|

[,]

Union operator in XPath results in a combination of node sets. JSONPath allows alternate names or array indices as a set.

n/a

[start:end:step]

array slice operator borrowed from ES4.

[]

?()

applies a filter (script) expression.

n/a

()

script expression, using the underlying script engine.

()

n/a

grouping in Xpath

JSONPath expressions can use the dot–notation

$.ccapiInfo.canonicalLink

or the bracket–notation

$['ccapiInfo']['canonicalLink']

for input paths. For the internal or output paths, they will always be converted to the more general bracket–notation.

Selecting on Multiple Criteria with JSONPath

Given an array of books, the following JSONPath applies two filters (e.g., "price" and "category") on the array to retrieve the name of author matching the criteria:

JMeter Temporary Root CA

Note that you need to "Configure your browser to use the JMeter Proxy" (see the section below) first. For the discussion only, we will show you the "JMeter Temporary Root CA" first.

This will start the JMeter proxy server which is used to intercept the browser requests. A file called ApacheJMeterTemporaryRootCA.crtwill be generated injmeter/binfolder and you will find a prompt showing below messages:

Installing the certificate in Firefox for HTTPS Recording

If you're recording SSL/TLS traffic (i.e., your site URL has https prefix), you need to install the certificate (i.e., ApacheJMeterTemporaryRootCA.crt) in your browser. So, JMeter could record encrypted traffic. If you don't know how to do it, readInstalling the JMeter CA certificate for HTTPS recording first.

For the Firefox (or FF) browser, you choose the following options (note that the configuration looks different in different FF versions):

Tools / Options

Advanced / Certificates

View Certificates

Authorities

Import …

Browse to the JMeter launch directory, and click on the fileApacheJMeterTemporaryRootCA.crt, pressOpen

Click View< and check that the certificate details agree with the ones displayed by the JMeter Test Script Recorder

If OK, select "Trust this CA to identify web sites", and press OK

Close dialog by pressing OK as necessary

After import, you can find a new entry on the Authorities list as shown below:

Configure Your Browser to Use the JMeter Proxy

Like many other web testing tools, JMeter records tests by inserting itself as an HTTP proxy between the browser and the web site. We use FF as our browser when using the JMeter HTTP(S) Test Script Recorder because, unlike Chrome and some other browsers, it does allows you to override system-wide configuration for its proxy settings (see also [8]).

Configure Firefox to use localhost (127.0.0.1) on port 8080 (Note that you also need to set the Port to be 8080 in HTTP(S) Test Script Recorder) as its proxy for all traffic by following these steps:[7]

Open Firefox

Go to the Preferences menu

From the tool bar, click Edit → Preferences (or Tools → Preferences or type about:preferences#advanced as URL). This should bring up the options.

Click on the Advanced tab

Then Network tab

In the "Connection" section, click on "Settings..."

Select the "Manual proxy configuration" radio button

Set HTTP Proxy to "localhost" and Port to "8080"

Check "Use this proxy server for all protocols"

Click OK and exit the Preferences menu

Note: When Firefox is configured to use JMeter's Script Recorder as a proxy, it will only work properly if the Script Recorder is running.

Recording Tips

When you record, you may want to consider the following extra configurations:

To generate a “virtual” sample representing a real page to measure aggregate times of all nested samples (i.e., embedded resources―images, styles, scripts, recordings or anything that seems like a separate request).

Disclaimer

The statements and opinions expressed here are my own and do not necessarily represent those of Oracle.For your computer health, follow me @xmlandmore. To improve your personal health, follow me @travel2health.

About Me

Healthy pursuits are like traveling. We know there is a wonderland called wellness. But, there are no fixed routes to reach there. The pursuits need effort and determination. We cannot act like tourists who don't know where they've been. We must take notes of warning signs sent by our bodies.

On the journey to wellness, there are many dangers to be avoided; there are many footsteps to be taken; unfortunately, there are no short-cuts.

Travelers walking in the night follow North Star. Healthy pursuits work similarly. We know our goal; we know the signposts; we know the dangers on the road; we can adjust pace if we are tired; we can change travel plans due to the weather. But, We walk steadily and persistently. With my companionship, hopefully, your journey will be made easier.