title: Jmeter: using a Beanshell Assertion to test a null JSON value
body: <p>SI'm trying to test a JSON value that may be = null. </p>
  
  <p>First I tried using jp@gc - JSON Path Assertion. but that doesn't appear to return anything or define the variable if it encounters a null value. </p>
  
  <p>So I was trying to get it to work like this: </p>
  
  <ul>
  <li>use jp@gc - JSON Path Extractor to try to extract the value to a variable.</li>
  <li>use Beanshell Assertion to test to see if the variable exists or has a null value</li>
  <li>If the variable does not exist, or exists and has a null value, I know that the JSON value was null.</li>
  </ul>
  
  <p>I haven't written any scripts with Jmeter before, so I may be doing something obviously wrong, but here is what I've tried in the Beanshell Assertion: </p>
  
  <pre><code>try {
    String myValue = vars.get("myValue");
    log.info("myValue =" + myValue);
  }
  catch (e) {
    log.info( "caught exception: "+e );
    String myValue = null;
  }
  
  
  if (myValue.length() &gt; 0  &amp;&amp; myValue != 0 ){
   Failure = true;
   FailureMessage = "myValue was " + myValue + ".";
  }
  else{
    Failure = false;
  }
  </code></pre>
  
  <p>For this test, a null value actually passes the test.</p>
  
  <p>The problem I'm running into is that the try/catch block doesn't work. Instead, I see the following message in the log:</p>
  
  <pre><code>jmeter.assertions.BeanShellAssertion: org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval    Sourced file: inline evaluation of: ``import org.apache.jmeter.util.JMeterUtils; try {   //myValue = JMeterUtils.get . . . '' : Attempt to resolve method: length() on undefined variable or class name: myValue
  </code></pre>
  
  <p>Can anyone tell me what I'm doing wrong and/or how to get this test of a null JSON value to work? </p>