Return-Path: X-Original-To: apmail-jmeter-user-archive@www.apache.org Delivered-To: apmail-jmeter-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 191FF10E98 for ; Tue, 25 Nov 2014 03:58:26 +0000 (UTC) Received: (qmail 35654 invoked by uid 500); 25 Nov 2014 03:58:25 -0000 Delivered-To: apmail-jmeter-user-archive@jmeter.apache.org Received: (qmail 35611 invoked by uid 500); 25 Nov 2014 03:58:25 -0000 Mailing-List: contact user-help@jmeter.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "JMeter Users List" Delivered-To: mailing list user@jmeter.apache.org Received: (qmail 35600 invoked by uid 99); 25 Nov 2014 03:58:25 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 25 Nov 2014 03:58:25 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of mangaroo@gmail.com designates 209.85.223.175 as permitted sender) Received: from [209.85.223.175] (HELO mail-ie0-f175.google.com) (209.85.223.175) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 25 Nov 2014 03:57:59 +0000 Received: by mail-ie0-f175.google.com with SMTP id at20so9968343iec.6 for ; Mon, 24 Nov 2014 19:57:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=oDHpmMKz6ZuoVJ8ULCjeS9L1aAOckJ0thOtexRhaHFo=; b=On+hElXiKa5KPsD35lb0eh9IoD+Q0Y5NZtcLBLGmmuFWVkvqaiQAeTon4/QlM8QHNP EWrQaYp+g80wh/Xpg+0WJpvn4KvFbN3SEQ7R90G2mrhgcSlZexpGEwaQ+knPBA+nmpoS XEWmzrg+BM86WJHyer3yr9y8dH4ixmEM6APo6ZXCu7J1v6V30M5ETmm5rB3qgPzXJ3Md 4zRi0N+HmasZfOViruBLPPougNwK92RtVlMIIxhoZL7QMiJ8qUXgBMLY0Qf3pq6EaUXq nbXedVvTjpO3TIyEE9wkCSdqtL3pD6SjXQ+f63ddLXDbcyTOuZjEQHf1UC8ayoW6nQek Zyxg== MIME-Version: 1.0 X-Received: by 10.107.12.234 with SMTP id 103mr20807352iom.71.1416887878118; Mon, 24 Nov 2014 19:57:58 -0800 (PST) Received: by 10.107.19.169 with HTTP; Mon, 24 Nov 2014 19:57:58 -0800 (PST) Date: Mon, 24 Nov 2014 19:57:58 -0800 Message-ID: Subject: JSON to string in javascript via BSF post processor, etc.? Seem to come across a problem. A bug? Any help or tips? From: David Luu To: JMeter Users List Content-Type: multipart/alternative; boundary=001a113f8fcaa973170508a6eaca X-Virus-Checked: Checked by ClamAV on apache.org --001a113f8fcaa973170508a6eaca Content-Type: text/plain; charset=UTF-8 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_g=1 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 http://theworkaholic.blogspot.com/2012/05/json-in-jmeter.html 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 --001a113f8fcaa973170508a6eaca--