You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jmeter.apache.org by Roberto Braga <ro...@sociale.it> on 2016/10/17 14:17:01 UTC

problem with json path extractor

I'm having a problem not sure if it is a bug or not.
Making the long story short.
I use jmeter 3.0 and bundled json path extractor with some rest api to 
make subsequent calls with foreach.

Lets say we have this scenario
country api -> region api ->city api->shop list
Get the country list and extract the array of country id and pass it to 
a foreach get regions list for each country, another call to region api 
and exctract the cities from the result

Generally everithing works, I get an array and the foreach works as 
expected.
But there are situation where I get only one result, because for 
instance there is only one region in the country.
In this case json path extractor do not give an array but a simple 
string var. This cause the following foreach to not get executed.
I'm not sure if this is the normal behaviour but this completely broke 
my script.
Another strange thinks is that I used the debug sampler to monitor the 
script  and the array never appear there but it exist since the foreach 
get executed, the var appear only when is a string.

Here is a debug example:

idCountryList_1=37
idCountryList_2=38
idCountryList_ALL=37,38
idCountryList_matchNr=2
idR=8
idRegioneList_1=8
idRegioneList_2=12
idRegioneList_3=3
idRegioneList_ALL=8,12,3
idRegioneList_matchNr=3
idCityList=37006
idCityList_ALL=37006
idCityList_matchNr=1


for idCountryList I expect to see as first line something like
idCountryList = [37, 38]
While idCityList appear because is not an array since the json contain 
just one result.
In this real example after extracting  the city list I have another api 
call that do not get executed because idCityList is not an array so the 
foreach get jumped.
I hope I've been clear.
Thank for any support
Roberto





-- 
"Ai sensi e per gli effetti della legge sulla tutela dei dati personali 
(D.lgs 196/2003),
le informazioni contenute nella presente @mail sono di natura riservata e 
destinate
ad un uso aziendale-lavorativo con esclusione di utilizzi ad uso personale; 
come tali,
pertanto, sono riservate esclusivamente ai destinatari sopra indicati. E' 
proibito leggere,
copiare, usare o diffondere il contenuto della presente @mail senza 
autorizzazione.
Se avete ricevuto questa @mail per errore, siete pregati di rispedire la 
stessa al mittente.
Grazie"

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
For additional commands, e-mail: user-help@jmeter.apache.org


Re: problem with json path extractor

Posted by Philippe Mouawad <ph...@gmail.com>.
Thank you Roberto.
It's very encouraging to have such kind words from happy users :-) Such
feedback is unfortunately not frequent enough.

And thanks for your contribution and your time.
Regards



On Fri, Oct 21, 2016 at 10:00 PM, Roberto Braga <ro...@sociale.it>
wrote:

> thank you all for the wonderfull jemeter and the prompt support
>
>
>
> Il 21/10/2016 21:09, Felix Schumacher ha scritto:
>
>> Am 21.10.2016 um 11:54 schrieb Roberto Braga:
>>
>>> I have attached a patch and two test cases, that show the behaviour for
>>>> Regex and (modified) JSON Extractor.
>>>>
>>>
>>> Is this patch already in the nightly build?
>>>
>>>
>>> I committed the patch. It should be in the next available nightly.
>>
>> Thanks for your investigations in this bug.
>>
>> Felix
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
>> For additional commands, e-mail: user-help@jmeter.apache.org
>>
>>
>
> --
> "Ai sensi e per gli effetti della legge sulla tutela dei dati personali
> (D.lgs 196/2003),
> le informazioni contenute nella presente @mail sono di natura riservata e
> destinate
> ad un uso aziendale-lavorativo con esclusione di utilizzi ad uso
> personale; come tali,
> pertanto, sono riservate esclusivamente ai destinatari sopra indicati. E'
> proibito leggere,
> copiare, usare o diffondere il contenuto della presente @mail senza
> autorizzazione.
> Se avete ricevuto questa @mail per errore, siete pregati di rispedire la
> stessa al mittente.
> Grazie"
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
> For additional commands, e-mail: user-help@jmeter.apache.org
>
>


-- 
Cordialement.
Philippe Mouawad.

Re: problem with json path extractor

Posted by Roberto Braga <ro...@sociale.it>.
thank you all for the wonderfull jemeter and the prompt support


Il 21/10/2016 21:09, Felix Schumacher ha scritto:
> Am 21.10.2016 um 11:54 schrieb Roberto Braga:
>>> I have attached a patch and two test cases, that show the behaviour for
>>> Regex and (modified) JSON Extractor.
>>
>> Is this patch already in the nightly build?
>>
>>
> I committed the patch. It should be in the next available nightly.
>
> Thanks for your investigations in this bug.
>
> Felix
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
> For additional commands, e-mail: user-help@jmeter.apache.org
>


-- 
"Ai sensi e per gli effetti della legge sulla tutela dei dati personali 
(D.lgs 196/2003),
le informazioni contenute nella presente @mail sono di natura riservata e 
destinate
ad un uso aziendale-lavorativo con esclusione di utilizzi ad uso personale; 
come tali,
pertanto, sono riservate esclusivamente ai destinatari sopra indicati. E' 
proibito leggere,
copiare, usare o diffondere il contenuto della presente @mail senza 
autorizzazione.
Se avete ricevuto questa @mail per errore, siete pregati di rispedire la 
stessa al mittente.
Grazie"

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
For additional commands, e-mail: user-help@jmeter.apache.org


Re: problem with json path extractor

Posted by Felix Schumacher <fe...@internetallee.de>.
Am 21.10.2016 um 11:54 schrieb Roberto Braga:
>> I have attached a patch and two test cases, that show the behaviour for
>> Regex and (modified) JSON Extractor.
>
> Is this patch already in the nightly build?
>
>
I committed the patch. It should be in the next available nightly.

Thanks for your investigations in this bug.

Felix


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
For additional commands, e-mail: user-help@jmeter.apache.org


Re: problem with json path extractor

Posted by Roberto Braga <ro...@sociale.it>.
>I have attached a patch and two test cases, that show the behaviour for
>Regex and (modified) JSON Extractor.

Is this patch already in the nightly build?


-- 
"Ai sensi e per gli effetti della legge sulla tutela dei dati personali 
(D.lgs 196/2003),
le informazioni contenute nella presente @mail sono di natura riservata e 
destinate
ad un uso aziendale-lavorativo con esclusione di utilizzi ad uso personale; 
come tali,
pertanto, sono riservate esclusivamente ai destinatari sopra indicati. E' 
proibito leggere,
copiare, usare o diffondere il contenuto della presente @mail senza 
autorizzazione.
Se avete ricevuto questa @mail per errore, siete pregati di rispedire la 
stessa al mittente.
Grazie"

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
For additional commands, e-mail: user-help@jmeter.apache.org


Re: problem with json path extractor

Posted by Philippe Mouawad <ph...@gmail.com>.
+1

On Thu, Oct 20, 2016 at 9:43 PM, Felix Schumacher <
felix.schumacher@internetallee.de> wrote:

> Am 20.10.2016 um 16:31 schrieb Felix Schumacher:
>
>> Am 20.10.2016 16:01, schrieb Roberto Braga:
>>
>>> I think there is a bug in the file
>>>
>>> apache-jmeter-3.0-src/src/components/org/apache/jmeter/extra
>>> ctor/json/jsonpath/JSONPostProcessor.java
>>>
>>>
>>> at line 163, there is the else where i goes if only one match
>>>
>>
>> The below src code is not in sync with the current code.
>>
>> But I think the important step for you is to place an additional var with
>> 'name_1' into vars in the case, when only one element is found and -1 is
>> used to indicate, that all elements are wanted.
>> If you want to update your patch you could have a look at the current
>> trunk and use the function stringify(Object).
>>
> After comparing the current behaviour of JSON Extractor with that of the
> Regex Extractor, I think we should extract to <varname>_1 only, when
> matchNumber is -1 and only one element could be matched.
>
> I have attached a patch and two test cases, that show the behaviour for
> Regex and (modified) JSON Extractor.
>
> Regards,
>  Felix
>
>
>> Regards,
>>  Felix
>>
>>
>>> } else {
>>>
>>>     // else just one value extracted
>>>
>>>     Object obj = extractedValues.get(0);
>>>
>>>     String objAsString =
>>>
>>>             obj != null ? obj.toString() : ""; //$NON-NLS-1$
>>>
>>> *     vars.put(currentRefName, *
>>>
>>> *             objAsString); *
>>>
>>> *     if (matchNumber < 0 && getComputeConcatenation()) {*
>>>
>>> *         vars.put(currentRefName + ALL_SUFFIX, objAsString);*
>>>
>>> *     }*
>>>
>>> }
>>>
>>>
>>> The part which set the vars  is worng it should be like the following:
>>>
>>> } else {
>>>
>>>     // else just one value extracted
>>>
>>>     Object obj = extractedValues.get(0);
>>>
>>>     String objAsString =
>>>
>>>             obj != null ? obj.toString() : ""; //$NON-NLS-1$
>>>
>>> *     if (matchNumber < 0 && getComputeConcatenation()) {*
>>>
>>> *         vars.put(currentRefName + "_1", *
>>>
>>> *                 objAsString);*
>>>
>>> *         vars.put(currentRefName + ALL_SUFFIX, objAsString);*
>>>
>>> *     } else {*
>>>
>>> *         vars.put(currentRefName, *
>>>
>>> *                 objAsString);*
>>>
>>> *     }*
>>>
>>> }
>>>
>>>
>>> In this way it respect the matchNumber docs specification even if only
>>> one value is extracted.
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
>> For additional commands, e-mail: user-help@jmeter.apache.org
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
> For additional commands, e-mail: user-help@jmeter.apache.org
>



-- 
Cordialement.
Philippe Mouawad.

Re: problem with json path extractor

Posted by Felix Schumacher <fe...@internetallee.de>.
Am 20.10.2016 um 16:31 schrieb Felix Schumacher:
> Am 20.10.2016 16:01, schrieb Roberto Braga:
>> I think there is a bug in the file
>>
>> apache-jmeter-3.0-src/src/components/org/apache/jmeter/extractor/json/jsonpath/JSONPostProcessor.java 
>>
>>
>>
>> at line 163, there is the else where i goes if only one match
>
> The below src code is not in sync with the current code.
>
> But I think the important step for you is to place an additional var 
> with 'name_1' into vars in the case, when only one element is found 
> and -1 is used to indicate, that all elements are wanted.
> If you want to update your patch you could have a look at the current 
> trunk and use the function stringify(Object).
After comparing the current behaviour of JSON Extractor with that of the 
Regex Extractor, I think we should extract to <varname>_1 only, when 
matchNumber is -1 and only one element could be matched.

I have attached a patch and two test cases, that show the behaviour for 
Regex and (modified) JSON Extractor.

Regards,
  Felix
>
> Regards,
>  Felix
>
>>
>> } else {
>>
>>     // else just one value extracted
>>
>>     Object obj = extractedValues.get(0);
>>
>>     String objAsString =
>>
>>             obj != null ? obj.toString() : ""; //$NON-NLS-1$
>>
>> *     vars.put(currentRefName, *
>>
>> *             objAsString); *
>>
>> *     if (matchNumber < 0 && getComputeConcatenation()) {*
>>
>> *         vars.put(currentRefName + ALL_SUFFIX, objAsString);*
>>
>> *     }*
>>
>> }
>>
>>
>> The part which set the vars  is worng it should be like the following:
>>
>> } else {
>>
>>     // else just one value extracted
>>
>>     Object obj = extractedValues.get(0);
>>
>>     String objAsString =
>>
>>             obj != null ? obj.toString() : ""; //$NON-NLS-1$
>>
>> *     if (matchNumber < 0 && getComputeConcatenation()) {*
>>
>> *         vars.put(currentRefName + "_1", *
>>
>> *                 objAsString);*
>>
>> *         vars.put(currentRefName + ALL_SUFFIX, objAsString);*
>>
>> *     } else {*
>>
>> *         vars.put(currentRefName, *
>>
>> *                 objAsString);*
>>
>> *     }*
>>
>> }
>>
>>
>> In this way it respect the matchNumber docs specification even if only
>> one value is extracted.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
> For additional commands, e-mail: user-help@jmeter.apache.org
>


Re: problem with json path extractor

Posted by Felix Schumacher <fe...@internetallee.de>.
Am 20.10.2016 16:01, schrieb Roberto Braga:
> I think there is a bug in the file
> 
> apache-jmeter-3.0-src/src/components/org/apache/jmeter/extractor/json/jsonpath/JSONPostProcessor.java
> 
> 
> at line 163, there is the else where i goes if only one match

The below src code is not in sync with the current code.

But I think the important step for you is to place an additional var 
with 'name_1' into vars in the case, when only one element is found and 
-1 is used to indicate, that all elements are wanted.
If you want to update your patch you could have a look at the current 
trunk and use the function stringify(Object).

Regards,
  Felix

> 
> } else {
> 
>     // else just one value extracted
> 
>     Object obj = extractedValues.get(0);
> 
>     String objAsString =
> 
>             obj != null ? obj.toString() : ""; //$NON-NLS-1$
> 
> *     vars.put(currentRefName, *
> 
> *             objAsString); *
> 
> *     if (matchNumber < 0 && getComputeConcatenation()) {*
> 
> *         vars.put(currentRefName + ALL_SUFFIX, objAsString);*
> 
> *     }*
> 
> }
> 
> 
> The part which set the vars  is worng it should be like the following:
> 
> } else {
> 
>     // else just one value extracted
> 
>     Object obj = extractedValues.get(0);
> 
>     String objAsString =
> 
>             obj != null ? obj.toString() : ""; //$NON-NLS-1$
> 
> *     if (matchNumber < 0 && getComputeConcatenation()) {*
> 
> *         vars.put(currentRefName + "_1", *
> 
> *                 objAsString);*
> 
> *         vars.put(currentRefName + ALL_SUFFIX, objAsString);*
> 
> *     } else {*
> 
> *         vars.put(currentRefName, *
> 
> *                 objAsString);*
> 
> *     }*
> 
> }
> 
> 
> In this way it respect the matchNumber docs specification even if only
> one value is extracted.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
For additional commands, e-mail: user-help@jmeter.apache.org


Re: problem with json path extractor

Posted by Roberto Braga <ro...@sociale.it>.
I think there is a bug in the file

apache-jmeter-3.0-src/src/components/org/apache/jmeter/extractor/json/jsonpath/JSONPostProcessor.java


at line 163, there is the else where i goes if only one match

} else {

     // else just one value extracted

     Object obj = extractedValues.get(0);

     String objAsString =

             obj != null ? obj.toString() : ""; //$NON-NLS-1$

*     vars.put(currentRefName, *

*             objAsString); *

*     if (matchNumber < 0 && getComputeConcatenation()) {*

*         vars.put(currentRefName + ALL_SUFFIX, objAsString);*

*     }*

}


The part which set the vars  is worng it should be like the following:

} else {

     // else just one value extracted

     Object obj = extractedValues.get(0);

     String objAsString =

             obj != null ? obj.toString() : ""; //$NON-NLS-1$

*     if (matchNumber < 0 && getComputeConcatenation()) {*

*         vars.put(currentRefName + "_1", *

*                 objAsString);*

*         vars.put(currentRefName + ALL_SUFFIX, objAsString);*

*     } else {*

*         vars.put(currentRefName, *

*                 objAsString);*

*     }*

}


In this way it respect the matchNumber docs specification even if only 
one value is extracted.





-- 
"Ai sensi e per gli effetti della legge sulla tutela dei dati personali 
(D.lgs 196/2003),
le informazioni contenute nella presente @mail sono di natura riservata e 
destinate
ad un uso aziendale-lavorativo con esclusione di utilizzi ad uso personale; 
come tali,
pertanto, sono riservate esclusivamente ai destinatari sopra indicati. E' 
proibito leggere,
copiare, usare o diffondere il contenuto della presente @mail senza 
autorizzazione.
Se avete ricevuto questa @mail per errore, siete pregati di rispedire la 
stessa al mittente.
Grazie"

Re: problem with json path extractor

Posted by Roberto Braga <ro...@sociale.it>.
The problem persist, but I found out why. I attach a testing sample to 
explain it.

At first I have to admit that I had a some misunderstanding

  * JSON extractor gives multiples vars as result, not an array
  * the foreach loop (it loop trough  varname_1..N and not on array)

I was misguided by imprecise and poor article on rest api testing, I 
should have read carefully the docs first.

Anyway there is still a problem.

I think that the json component ignore the Match Numbers = -1 when it 
match only one

 From the docs:

Match Numbers
If the JSON Path query leads to many results, you can choose which 
one(s) to extract as Variables:

     0 : means random (Default Value)
     -1 means extract all results, they will be named as variable name_N 
(where N goes from 1 to Number of results
     X : means extract the Xth result. If this Xth is greater than 
number of matches, then nothing is returned. Default value will be used

When JSON extractor match only one result it return the var name without 
the counter number even if Match Numbers = -1

In the example I attached the problem is evident.







Il 17/10/2016 22:47, Philippe Mouawad ha scritto:
> Hello,
> There are some fixes in nightly build.
> Could you try it ?
> http://jmeter.apache.org/nightly.html
>
> If issue persists, can you create a demo Test plan using Java Request where
> you put the JSON in ResponseData and the JSON-PATH POST PROCESSOR that you
> use.
>
> Thank you
>
> On Mon, Oct 17, 2016 at 4:17 PM, Roberto Braga <ro...@sociale.it>
> wrote:
>
>> I'm having a problem not sure if it is a bug or not.
>> Making the long story short.
>> I use jmeter 3.0 and bundled json path extractor with some rest api to
>> make subsequent calls with foreach.
>>
>> Lets say we have this scenario
>> country api -> region api ->city api->shop list
>> Get the country list and extract the array of country id and pass it to a
>> foreach get regions list for each country, another call to region api and
>> exctract the cities from the result
>>
>> Generally everithing works, I get an array and the foreach works as
>> expected.
>> But there are situation where I get only one result, because for instance
>> there is only one region in the country.
>> In this case json path extractor do not give an array but a simple string
>> var. This cause the following foreach to not get executed.
>> I'm not sure if this is the normal behaviour but this completely broke my
>> script.
>> Another strange thinks is that I used the debug sampler to monitor the
>> script  and the array never appear there but it exist since the foreach get
>> executed, the var appear only when is a string.
>>
>> Here is a debug example:
>>
>> idCountryList_1=37
>> idCountryList_2=38
>> idCountryList_ALL=37,38
>> idCountryList_matchNr=2
>> idR=8
>> idRegioneList_1=8
>> idRegioneList_2=12
>> idRegioneList_3=3
>> idRegioneList_ALL=8,12,3
>> idRegioneList_matchNr=3
>> idCityList=37006
>> idCityList_ALL=37006
>> idCityList_matchNr=1
>>
>>
>> for idCountryList I expect to see as first line something like
>> idCountryList = [37, 38]
>> While idCityList appear because is not an array since the json contain
>> just one result.
>> In this real example after extracting  the city list I have another api
>> call that do not get executed because idCityList is not an array so the
>> foreach get jumped.
>> I hope I've been clear.
>> Thank for any support
>> Roberto
>>
>>
>>
>>
>>
>> --
>> "Ai sensi e per gli effetti della legge sulla tutela dei dati personali
>> (D.lgs 196/2003),
>> le informazioni contenute nella presente @mail sono di natura riservata e
>> destinate
>> ad un uso aziendale-lavorativo con esclusione di utilizzi ad uso
>> personale; come tali,
>> pertanto, sono riservate esclusivamente ai destinatari sopra indicati. E'
>> proibito leggere,
>> copiare, usare o diffondere il contenuto della presente @mail senza
>> autorizzazione.
>> Se avete ricevuto questa @mail per errore, siete pregati di rispedire la
>> stessa al mittente.
>> Grazie"
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
>> For additional commands, e-mail: user-help@jmeter.apache.org
>>
>>
>


-- 
"Ai sensi e per gli effetti della legge sulla tutela dei dati personali 
(D.lgs 196/2003),
le informazioni contenute nella presente @mail sono di natura riservata e 
destinate
ad un uso aziendale-lavorativo con esclusione di utilizzi ad uso personale; 
come tali,
pertanto, sono riservate esclusivamente ai destinatari sopra indicati. E' 
proibito leggere,
copiare, usare o diffondere il contenuto della presente @mail senza 
autorizzazione.
Se avete ricevuto questa @mail per errore, siete pregati di rispedire la 
stessa al mittente.
Grazie"

Re: problem with json path extractor

Posted by Philippe Mouawad <ph...@gmail.com>.
Hello,
There are some fixes in nightly build.
Could you try it ?
http://jmeter.apache.org/nightly.html

If issue persists, can you create a demo Test plan using Java Request where
you put the JSON in ResponseData and the JSON-PATH POST PROCESSOR that you
use.

Thank you

On Mon, Oct 17, 2016 at 4:17 PM, Roberto Braga <ro...@sociale.it>
wrote:

> I'm having a problem not sure if it is a bug or not.
> Making the long story short.
> I use jmeter 3.0 and bundled json path extractor with some rest api to
> make subsequent calls with foreach.
>
> Lets say we have this scenario
> country api -> region api ->city api->shop list
> Get the country list and extract the array of country id and pass it to a
> foreach get regions list for each country, another call to region api and
> exctract the cities from the result
>
> Generally everithing works, I get an array and the foreach works as
> expected.
> But there are situation where I get only one result, because for instance
> there is only one region in the country.
> In this case json path extractor do not give an array but a simple string
> var. This cause the following foreach to not get executed.
> I'm not sure if this is the normal behaviour but this completely broke my
> script.
> Another strange thinks is that I used the debug sampler to monitor the
> script  and the array never appear there but it exist since the foreach get
> executed, the var appear only when is a string.
>
> Here is a debug example:
>
> idCountryList_1=37
> idCountryList_2=38
> idCountryList_ALL=37,38
> idCountryList_matchNr=2
> idR=8
> idRegioneList_1=8
> idRegioneList_2=12
> idRegioneList_3=3
> idRegioneList_ALL=8,12,3
> idRegioneList_matchNr=3
> idCityList=37006
> idCityList_ALL=37006
> idCityList_matchNr=1
>
>
> for idCountryList I expect to see as first line something like
> idCountryList = [37, 38]
> While idCityList appear because is not an array since the json contain
> just one result.
> In this real example after extracting  the city list I have another api
> call that do not get executed because idCityList is not an array so the
> foreach get jumped.
> I hope I've been clear.
> Thank for any support
> Roberto
>
>
>
>
>
> --
> "Ai sensi e per gli effetti della legge sulla tutela dei dati personali
> (D.lgs 196/2003),
> le informazioni contenute nella presente @mail sono di natura riservata e
> destinate
> ad un uso aziendale-lavorativo con esclusione di utilizzi ad uso
> personale; come tali,
> pertanto, sono riservate esclusivamente ai destinatari sopra indicati. E'
> proibito leggere,
> copiare, usare o diffondere il contenuto della presente @mail senza
> autorizzazione.
> Se avete ricevuto questa @mail per errore, siete pregati di rispedire la
> stessa al mittente.
> Grazie"
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
> For additional commands, e-mail: user-help@jmeter.apache.org
>
>


-- 
Cordialement.
Philippe Mouawad.