The Burp Suite User Forum was discontinued on the 1st November 2024.

Burp Suite User Forum

For support requests, go to the Support Center. To discuss with other Burp users, head to our Discord page.

SUPPORT CENTER DISCORD

Not able to convert string to JSON object in Burp Extension using Montoya API

Mukund | Last updated: Apr 13, 2024 09:22AM UTC

Gson gson = new GsonBuilder().setPrettyPrinting().create(); String jsonString = "{ \"name\" : \"John\", \"age\" : \"20\", \"address\" : \"some address\" }"; JsonElement jelem = gson.fromJson(jsonString, JsonElement.class); JsonObject jobj = jelem.getAsJsonObject(); String name = jobj.get("name").getAsString(); logging.logToOutput(name); This is an example code I am trying to use, so that I can read JSON body from actual HTTP response, but anything beyond the statement `JsonElement jelem = gson.fromJson(jsonString, JsonElement.class);` doesn't seem to work. I have tried org.json.JSONObject as well, but that also doesn't work. Doesn't throw any error and doesn't work. Same statements written in a Java program works perfectly, but doesn't work when executing in Burp Suite. How can I convert the response body string to JSON to extract data for work?

Hannah, PortSwigger Agent | Last updated: Apr 15, 2024 04:13PM UTC

Hi If you wrap your JSON object creation code into a try/catch block, do you find that an exception gets thrown?

Mukund | Last updated: Apr 21, 2024 02:35PM UTC

try { Gson gson = new GsonBuilder().setPrettyPrinting().create(); String jsonString = "{ \"name\" : \"John\", \"age\" : \"20\", \"address\" : \"some address\" }"; JsonElement jelem = gson.fromJson(jsonString, JsonElement.class); JsonObject jobj = jelem.getAsJsonObject(); String name = jobj.get("name").getAsString(); logging.logToOutput(name); } catch(Exception e2) { logging.logToError(e2.getMessage()); } I tried this code by using try catch block, but still I am not able to get any log in the Error tab in Burp suite extension.

Hannah, PortSwigger Agent | Last updated: Apr 22, 2024 09:40AM UTC