jmeter-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mark Miller <>
Subject Re: JSON to string in javascript via BSF post processor, etc.? Seem to come across a problem. A bug? Any help or tips?
Date Tue, 25 Nov 2014 04:54:22 GMT
Just a couple ideas that may help. If you need that data downstream, have
you experimented with vars.putObject instead of just strings?

We've been having great success with JRuby and JSR223 scripting. (Granted,
we're doing functional testing exclusively so the JRuby overhead doesn't
bother us.)

It's been pretty powerful to build up a ruby hash and pass it around via
putObject and getObject. Then run ruby json or rexml on it to press it into
the right string formats for various purposes.

It's been awhile since I tried to see if JSON stringify support was there
(in rhino, yes?). I'll have to take another look at that.

Good luck...


On Mon, Nov 24, 2014 at 8:57 PM, David Luu <> wrote:

> I was wondering if anyone has dealt with JSON data and the need to
> stringify it at some point and doing this in JMeter, say with BSF sampler
> for javascript?
> Any tips on that would be appreciated.
> I gave it a try and noticed that JMeter, at least as of version 2.9
> r1437961 that I'm using, seems to support JSON.stringify(), or using it
> doesn't cause any errors.
> However, in one situation, it fails to work. I can't share the full test
> plan but here's a snippet around the issue:
> //after HTTP sampler, we process JSON response in BSF post processor in
> javascript
> eval('var jsonResponse = ' + prev.getResponseDataAsString());
> jsonResponse.cacheOnly = false;
> jsonResponse.someItemId = vars.get("SOMEITEMID");
> //...some other stuff dealing with updating JSON object member values
> vars.put("testVar", jsonResponse.someItemId);
> vars.put("JSON_OBJ_AS_STR", JSON.stringify(jsonResponse));
> I'm reusing JSON_OBJ_AS_STR or can be a new JMeter variable.
> If I set JSON object member someItemId, then the stringify fails (without
> any complain from JMeter other than test failure at some point). Using
> debug sampler after this, I notice that JSON_OBJ_AS_STR isn't updated as
> expected (using old value) or the new variable isn't defined/set, although
> testVar is defined correctly. If I omit defining new member "someItemId"
> and setting it's value, then the stringify works fine. But I need both
> things together.
> SOMEITEMID is actually a JMeter variable set by a Regular Expression
> Extractor that is set to match a single match group in parenthesis in the
> regex.
> SOMEITEMID =14179242
> SOMEITEMID_g0=someText someMoreText" id="14179242"
> SOMEITEMID_g1=14179242
> I also tried using  SOMEITEMID_g1 instead of base variable, didn't make a
> difference.
> Is the problem to do with regular expression matched variable and
> JSON.stringify used together?
> I guess I could look for alternate javascript solution, or worst case swap
> to try doing it in Java like
> it's just that javascript is simpler to deal with if I can. I don't suppose
> a newer version of Jmeter fixes this issue...
> I could look into JSONPath related route, but as I'm dealing with multiple
> updates to JSON object data, it seems easier to do in code whether
> javascript, Java, etc.
> Thanks for reading. Any feedback appreciated,
> David

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message