https://bz.apache.org/bugzilla/show_bug.cgi?id=59149

            Bug ID: 59149
           Summary: Bean Shell not able to parse JSON where some special
                    characters are present in JSON Data(like # \)
           Product: JMeter
           Version: 2.13
          Hardware: Macintosh
            Status: NEW
          Severity: normal
          Priority: P2
         Component: HTTP
          Assignee: [email protected]
          Reporter: [email protected]

Created attachment 33652
  --> https://bz.apache.org/bugzilla/attachment.cgi?id=33652&action=edit
JMX file and data file been used is given as an attachment

I am able to parse JSON without any issue while running same java code in
eclipse .But same code on Bean Shell Post processor gives error in log.Below
are data and log file given with sample code tried on both eclipse and Bean
Shell post processor.

JSON Data where parsing fails:
"streamProfiles": [{

        "mediaPlaylist":
"#EXT-X-STREAM-INF:BANDWIDTH=565400,AVERAGE-BANDWIDTH=565400,CODECS=\"avc1.77.30,mp4a.40.2\",RESOLUTION=640x360",
        "channels": 0,
        "mime_type": "audio\/x-mpegurl",
        "host":
"http:\/\/yahooios2-i.akamaihd.net\/hls\/live\/224964\/iosstream\/esports_us_main_highprofile\/master_514.m3u8",
    },  


Jmeter Log:
2016/03/08 12:05:02 INFO  - jmeter.util.BeanShellTestElement: Error in my
script Unexpected character (#) at position 0.
    at org.json.simple.parser.Yylex.yylex(Unknown Source)
    at org.json.simple.parser.JSONParser.nextToken(Unknown Source)
    at org.json.simple.parser.JSONParser.parse(Unknown Source)
    at org.json.simple.parser.JSONParser.parse(Unknown Source)
    at org.json.simple.parser.JSONParser.parse(Unknown Source)
    at sun.reflect.GeneratedMethodAccessor40.invoke(Unknown Source)
    at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at bsh.Reflect.invokeMethod(Reflect.java:134)
    at bsh.Reflect.invokeObjectMethod(Reflect.java:80)
    at bsh.Name.invokeMethod(Name.java:858)
    at bsh.BSHMethodInvocation.eval(BSHMethodInvocation.java:75)
    at bsh.BSHPrimaryExpression.eval(BSHPrimaryExpression.java:102)
    at bsh.BSHPrimaryExpression.eval(BSHPrimaryExpression.java:47)
    at bsh.BSHCastExpression.eval(BSHCastExpression.java:60)
    at bsh.BSHAssignment.eval(BSHAssignment.java:77)
    at bsh.BSHBlock.evalBlock(BSHBlock.java:130)
    at bsh.BSHBlock.eval(BSHBlock.java:80)
    at bsh.BSHBlock.eval(BSHBlock.java:46)
    at bsh.BSHTryStatement.eval(BSHTryStatement.java:86)
    at bsh.Interpreter.eval(Interpreter.java:645)
    at bsh.Interpreter.eval(Interpreter.java:739)
    at bsh.Interpreter.eval(Interpreter.java:728)
    at sun.reflect.GeneratedMethodAccessor35.invoke(Unknown Source)
    at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at
org.apache.jmeter.util.BeanShellInterpreter.bshInvoke(BeanShellInterpreter.java:170)
    at
org.apache.jmeter.util.BeanShellInterpreter.eval(BeanShellInterpreter.java:197)
    at
org.apache.jmeter.util.BeanShellTestElement.processFileOrScript(BeanShellTestElement.java:151)
    at
org.apache.jmeter.extractor.BeanShellPostProcessor.process(BeanShellPostProcessor.java:64)
    at
org.apache.jmeter.threads.JMeterThread.runPostProcessors(JMeterThread.java:750)
    at
org.apache.jmeter.threads.JMeterThread.process_sampler(JMeterThread.java:452)
    at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:261)
    at java.lang.Thread.run(Thread.java:745)

Another character which was creating issue while parsing:

2016/03/08 11:34:09 INFO  - jmeter.util.BeanShellTestElement: Error in my
script Unexpected character (\) at position 1.
    at org.json.simple.parser.Yylex.yylex(Unknown Source)
    at org.json.simple.parser.JSONParser.nextToken(Unknown Source)
    at org.json.simple.parser.JSONParser.parse(Unknown Source)
    at org.json.simple.parser.JSONParser.parse(Unknown Source)
    at org.json.simple.parser.JSONParser.parse(Unknown Source)
    at sun.reflect.GeneratedMethodAccessor40.invoke(Unknown Source)
    at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at bsh.Reflect.invokeMethod(Reflect.java:134)
    at bsh.Reflect.invokeObjectMethod(Reflect.java:80)
    at bsh.Name.invokeMethod(Name.java:858)
    at bsh.BSHMethodInvocation.eval(BSHMethodInvocation.java:75)
    at bsh.BSHPrimaryExpression.eval(BSHPrimaryExpression.java:102)
    at bsh.BSHPrimaryExpression.eval(BSHPrimaryExpression.java:47)
    at bsh.BSHCastExpression.eval(BSHCastExpression.java:60)
    at bsh.BSHAssignment.eval(BSHAssignment.java:77)
    at bsh.BSHBlock.evalBlock(BSHBlock.java:130)
    at bsh.BSHBlock.eval(BSHBlock.java:80)
    at bsh.BSHBlock.eval(BSHBlock.java:46)
    at bsh.BSHTryStatement.eval(BSHTryStatement.java:86)
    at bsh.Interpreter.eval(Interpreter.java:645)
    at bsh.Interpreter.eval(Interpreter.java:739)
    at bsh.Interpreter.eval(Interpreter.java:728)
    at sun.reflect.GeneratedMethodAccessor35.invoke(Unknown Source)
    at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at
org.apache.jmeter.util.BeanShellInterpreter.bshInvoke(BeanShellInterpreter.java:170)
    at
org.apache.jmeter.util.BeanShellInterpreter.eval(BeanShellInterpreter.java:197)
    at
org.apache.jmeter.util.BeanShellTestElement.processFileOrScript(BeanShellTestElement.java:151)
    at
org.apache.jmeter.extractor.BeanShellPostProcessor.process(BeanShellPostProcessor.java:64)
    at
org.apache.jmeter.threads.JMeterThread.runPostProcessors(JMeterThread.java:750)
    at
org.apache.jmeter.threads.JMeterThread.process_sampler(JMeterThread.java:452)
    at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:261)
    at java.lang.Thread.run(Thread.java:745)

To Parse JSON Below jar been used:
json-simple-1.1.jar

and below is sample code:
in Bean shell:
import org.json.simple.JSONObject;
import java.io.*;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
#String jsonString = prev.getResponseDataAsString();

FileReader reader = new
FileReader("/Users/balendrapathak/my-app/src/main/java/com/mycompany/app/json.txt");

log.info("This is Output Data: ");
JSONParser jsonParser = new JSONParser();
                JSONObject jsonobj = null;
        try {
            jsonobj = (JSONObject) jsonParser.parse(reader);
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            log.info("Error in my script", e);
            e.printStackTrace();
        }
        //System.out.println("This is object :"+jsonobj.toString());
        JSONObject obj= (JSONObject)jsonobj.get("query");
        JSONObject obj1= (JSONObject)obj.get("results");
        JSONArray objarr=(JSONArray) obj1.get("mediaObj");
        for(int i=0;i<objarr.size();i++){

            //System.out.println("Print all json oobject under mediaObj
:"+objarr.get(i).toString());
            JSONObject jsobj= (JSONObject) objarr.get(i);
            JSONArray ar=(JSONArray) jsobj.get("streamProfiles");
            JSONObject obj3= (JSONObject)ar.get(0);
            //System.out.println(obj3.get("host"));
            log.info("This is host extracted Data: "+host);

            }

Same code in eclipse runs properly.

Please help to understand if this is an issue or I need to do some
preprocessing before parsing.

-- 
You are receiving this mail because:
You are the assignee for the bug.

Reply via email to