You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jmeter.apache.org by Pulkit Singhal <pu...@gmail.com> on 2012/03/14 17:06:18 UTC

How to handle JSON to JS conversion corner cases in JMeter

When JMeter gets back a REST response (fyi - most of the colon symbols are
only there for indentation purposes) like this one:
:   :   :   :   "fields":
:   :   :   :   {
:   :   :   :   :   "name":"Here to Stay [RVG Edition]"
:   :   :   :   }

And the response is run through a BSF PostProcessor like so:
// Turn the JSON response into a JS object
var response = eval( "(" + prev.getResponseDataAsString() + ")" );

Then it ends up parsing the value this way:
fields.name =
Here to Stay
[
:   RVG Edition
]

It seems to me that the [RVG Edition] inside "Here to Stay [RVG Edition]"
is being interpreted as an array based on the above output.

Questions:
1) Is my assumption correct?
2) Has anyone run into this kind of corner case before when testing with
JMeter?
3) Is eval a bad way to interpret REST responses by converting them into JS
objects when it comes to data like this?
4) Is there workaround or an entirely different way to go about processing
REST responses?

Re: How to handle JSON to JS conversion corner cases in JMeter

Posted by Pulkit Singhal <pu...@gmail.com>.
Thank You everyone! Your responses were very helpful. I was using
Javascript in BSF to turn the JSON response into a JS object. The issue
that I saw apparently wasn't really an issue at all. The conversion
happened properly, I was apparently looking at the "view results tree" via
the show as "JSON" formatter. When I looked at it via the show as "Text"
formatter I realized that the actual data was fine. It was just an
additional lens through which I was choosing to view the data ... that made
it seem like there were problems.

On Wed, Mar 14, 2012 at 11:14 AM, karl <ka...@sitestress.eu> wrote:

> Did you try
> this:
> https://github.com/smartrics/**JMeterRestSampler<https://github.com/smartrics/JMeterRestSampler>
>
> or this:
> https://github.com/ty1er/**JMeterRestSampler<https://github.com/ty1er/JMeterRestSampler>
>
> or this:
> https://github.com/ATLANTBH/**jmeter-components<https://github.com/ATLANTBH/jmeter-components>
>
> ?
> regards
> karl
>
>
> Am 14.03.2012 17:06, schrieb Pulkit Singhal:
>
>  When JMeter gets back a REST response (fyi - most of the colon symbols are
>> only there for indentation purposes) like this one:
>> :   :   :   :   "fields":
>> :   :   :   :   {
>> :   :   :   :   :   "name":"Here to Stay [RVG Edition]"
>> :   :   :   :   }
>>
>> And the response is run through a BSF PostProcessor like so:
>> // Turn the JSON response into a JS object
>> var response = eval( "(" + prev.getResponseDataAsString() + ")" );
>>
>> Then it ends up parsing the value this way:
>> fields.name =
>> Here to Stay
>> [
>> :   RVG Edition
>> ]
>>
>> It seems to me that the [RVG Edition] inside "Here to Stay [RVG Edition]"
>> is being interpreted as an array based on the above output.
>>
>> Questions:
>> 1) Is my assumption correct?
>> 2) Has anyone run into this kind of corner case before when testing with
>> JMeter?
>> 3) Is eval a bad way to interpret REST responses by converting them into
>> JS
>> objects when it comes to data like this?
>> 4) Is there workaround or an entirely different way to go about processing
>> REST responses?
>>
>>
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: user-unsubscribe@jmeter.**apache.org<us...@jmeter.apache.org>
> For additional commands, e-mail: user-help@jmeter.apache.org
>
>

Re: How to handle JSON to JS conversion corner cases in JMeter

Posted by karl <ka...@sitestress.eu>.
Did you try
this:
https://github.com/smartrics/JMeterRestSampler

or this:
https://github.com/ty1er/JMeterRestSampler

or this:
https://github.com/ATLANTBH/jmeter-components

?
regards
karl


Am 14.03.2012 17:06, schrieb Pulkit Singhal:
> When JMeter gets back a REST response (fyi - most of the colon symbols are
> only there for indentation purposes) like this one:
> :   :   :   :   "fields":
> :   :   :   :   {
> :   :   :   :   :   "name":"Here to Stay [RVG Edition]"
> :   :   :   :   }
>
> And the response is run through a BSF PostProcessor like so:
> // Turn the JSON response into a JS object
> var response = eval( "(" + prev.getResponseDataAsString() + ")" );
>
> Then it ends up parsing the value this way:
> fields.name =
> Here to Stay
> [
> :   RVG Edition
> ]
>
> It seems to me that the [RVG Edition] inside "Here to Stay [RVG Edition]"
> is being interpreted as an array based on the above output.
>
> Questions:
> 1) Is my assumption correct?
> 2) Has anyone run into this kind of corner case before when testing with
> JMeter?
> 3) Is eval a bad way to interpret REST responses by converting them into JS
> objects when it comes to data like this?
> 4) Is there workaround or an entirely different way to go about processing
> REST responses?
>


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


Re: How to handle JSON to JS conversion corner cases in JMeter

Posted by sebb <se...@gmail.com>.
On 14 March 2012 16:06, Pulkit Singhal <pu...@gmail.com> wrote:
> When JMeter gets back a REST response (fyi - most of the colon symbols are
> only there for indentation purposes) like this one:
> :   :   :   :   "fields":
> :   :   :   :   {
> :   :   :   :   :   "name":"Here to Stay [RVG Edition]"
> :   :   :   :   }
>
> And the response is run through a BSF PostProcessor like so:

Which BSF language are you using?

> // Turn the JSON response into a JS object
> var response = eval( "(" + prev.getResponseDataAsString() + ")" );
>
> Then it ends up parsing the value this way:
> fields.name =
> Here to Stay
> [
> :   RVG Edition
> ]
>
> It seems to me that the [RVG Edition] inside "Here to Stay [RVG Edition]"
> is being interpreted as an array based on the above output.
>
> Questions:
> 1) Is my assumption correct?
> 2) Has anyone run into this kind of corner case before when testing with
> JMeter?
> 3) Is eval a bad way to interpret REST responses by converting them into JS
> objects when it comes to data like this?
> 4) Is there workaround or an entirely different way to go about processing
> REST responses?

This is not really a JMeter question; JMeter just invokes the language
using the BSF API.

You might get more informed comment if you ask on the appropriate
language user list.

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