Problems with JSON Path Extractor (direct vs. query search)

366 views
Skip to first unread message

tomm...@gmail.com

unread,
Jan 7, 2015, 9:06:53 AM1/7/15
to jmeter-...@googlegroups.com
Hy all,

I am trying to work with JSON Path Extraction Plugin (jp@gc) to follow RESTful links in my JMeter tests.

My JSON String: 
{
 
"links": [
   
{
     
"rel": "link1",
     
"href": "http://localhost:8086/link1"
   
},
   
{
     
"rel": "link2",
     
"href": "http://localhost:8086/link2"
   
}
 
]
}


I am trying to access the link (href) via the real name like it is thought in the REST concept. But it looks like that the search query in the JSON path for the real name returns a list and that isn't correct parable from the Plugin. When I access one element directly all works fine for me. But of course it is not expected from the protocol that the elements are always on the same position in the JSON string.

In the Online Tool (http://ashphy.com/JSONPathOnlineEvaluator/) my JSON String and both results are correct. 

Example:

Direct Element JSON Path: 
$.links.[0].href

Online Tool Result:
JMeter jp@gc - JSON Path Extractor Result:
http://localhost:8086/link1


Via Rel-Name JSON Path:
$.links.[?(@.rel == 'link1')].href

Online Tool Result:
JMeter jp@gc - JSON Path Extractor Result:
["http:\/\/localhost:8086\/link1"]

Hope I have explained all understandable and that someone can help me.

Thx and regards from Germany


Tommy

Andrey Pohilko

unread,
Jan 7, 2015, 11:38:07 AM1/7/15
to jmeter-...@googlegroups.com, tomm...@gmail.com
Hi Tommy,

What do you expect to get in the case when multiple values might match?

--
Andrey

среда, 7 января 2015 г., 17:06:53 UTC+3 пользователь tomm...@gmail.com написал:

tomm...@gmail.com

unread,
Jan 7, 2015, 12:00:16 PM1/7/15
to jmeter-...@googlegroups.com, tomm...@gmail.com
Hi Andrey,

thx for your quick reply.

I would love to get just one String which I requested also: http://localhost:8086/link1

Like I also receive it when I request it with [0], because I need it to make again a new request.
Do you have a Idea how I can rewrite the JSON Path, or what would be possible to do in the Plugin?


Thx
Tommy

Srinivas Kotha

unread,
Jan 8, 2015, 2:43:21 AM1/8/15
to jmeter-...@googlegroups.com, tomm...@gmail.com
Hi Tommy,

I am not sure it would be the correct solution or not but i have used a regular expression extractor to resolve my problem.

My Challenge - I am working on web application in which we need to create a project (which generates a UUID and its a dynamic which needs to use for scripting) then create some subets which needs that UUID to move further.

Solution - By adding save response listener i have extracted UUID then passed it through regular expression. 

If you are also having similar problem then let me know i will help you.

-Srinivas  

jmore...@gmail.com

unread,
Oct 2, 2015, 4:18:03 PM10/2/15
to jmeter-plugins, tomm...@gmail.com
Andrey,
Are you saying that your JSON path extractor does not support queries? But if it does, what is the underlying language script that we should use in the JMeter context? I realize that a query could return more than one value, but couldn't it either throw an error or implement something like the RegEx Extractor?

gli...@gmail.com

unread,
Oct 4, 2015, 4:45:08 AM10/4/15
to jmeter-plugins, tomm...@gmail.com
This is by design so JSONPath queries could return multiple matching values. According to JSONPath syntax your query returns all links with "rel=link1" hence you're receiving an array of links (no matter if the array consists of one member only)

The options are:

  1. Downgrade the plugin to version <= 1.2.1 
  2. Change your JSONPath query to explicitly return first match only like
$.links.[?(@.rel == 'link1')].href[0]

You can also see Using the XPath Extractor in JMeter guide (scroll down to "Parsing JSON") for XPath to JSONPath mapping if you're comfortable with XPath and looking for a JSONPath equivalent.
Reply all
Reply to author
Forward
0 new messages