code: @Given("^I save element (in position \'(.+?)\' in )?\'(.+?)\' in environment variable \'(.+?)\'$")
      public void saveElementEnvironment(String foo, String position, String element, String envVar) throws Exception {
  
          Pattern pattern = Pattern.compile("^((.*)(\\.)+)(\\$.*)$");
          Matcher matcher = pattern.matcher(element);
          String json;
          String parsedElement;
  
          if (matcher.find()) {
              json = matcher.group(2);
              parsedElement = matcher.group(4);
          } else {
              json = commonspec.getResponse().getResponse();
              parsedElement = element;
          }
  
          String value = commonspec.getJSONPathString(json, parsedElement, position);
  
          ThreadProperty.set(envVar, value.replaceAll("\n", ""));
      }
docs: Save value for future use.
  <p>
  If element is a jsonpath expression (i.e. $.fragments[0].id), it will be
  applied over the last httpResponse.
  <p>
  If element is a jsonpath expression preceded by some other string
  (i.e. ["a","b",,"c"].$.[0]), it will be applied over this string.
  This will help to save the result of a jsonpath expression evaluated over
  previous stored variable.
  
  @param position position from a search result
  @param element  key in the json response to be saved
  @param envVar   thread environment variable where to store the value
  @throws IllegalAccessException    exception
  @throws IllegalArgumentException  exception
  @throws SecurityException         exception
  @throws NoSuchFieldException      exception
  @throws ClassNotFoundException    exception
  @throws InstantiationException    exception
  @throws InvocationTargetException exception
  @throws NoSuchMethodException     exception