Exercise A: Custom Editor Tab
Burp’s message editor ships with Raw, Pretty, and Hex tabs. The Pretty tab handles common formats like JSON out of the box, but some apps use encodings Burp doesn’t decode for you. When that happens, the message is hard to read.
The Montoya API lets you register your own editor tab. In this exercise you’ll add a JSON tab that appears whenever Burp shows a JSON response. The tab displays the body indented and readable. The same pattern (decide when the tab shows, transform the message, render it) extends to any decoder you find useful.
Note: Burp’s built-in Pretty tab already formats JSON. This exercise re-implements that on purpose as a clear, self-contained example: it shows you how to register an editor tab, decide when it appears, and render a transformed message. Apply the same pattern to formats Burp doesn’t handle out of the box.
Reference: customrequesteditortab in the Montoya API examples repo.
JavaDoc: userInterface().registerHttpResponseEditorProvider()
Table of contents
- The goal
- Before you start
- The provider and the editor
- How to approach it
- Check your work
- The complete extension
- Taking it further
The goal
Build a new JSON tab in the response editor. It should:
- Appear only for responses whose body is valid JSON.
- Show the body pretty-printed with indentation.
- Be read-only.
Before you start
Every exercise starts from PortSwigger’s extension starter project. If you haven’t set it up yet, the one-time steps are inline below; the full guide with troubleshooting lives on the overview page. You’ll know it’s working when the jar task (or ./gradlew jar) succeeds and the extension loads in Extensions without errors.
First time here? Set up the starter project (do this once)
You do this once. After that, every exercise is just editing code in the project you set up here.
1. Get the starter project. Either:
- In Burp, go to Extensions > APIs and click Download starter project. Save the
ExtensionTemplateProjectfolder. (Recommended.) - Or open the extension-template-project repo on GitHub, click Code > Download ZIP, and unzip it.
2. Open it in IntelliJ. Go to File > Open and select the project folder. When IntelliJ prompts you, let it auto-detect and configure Gradle. Then set the project JDK to 21, because Burp only runs extensions built for Java 21 or lower: in File > Project Structure > SDK, select an installed JDK 21, or click Download JDK and choose Temurin 21. You don’t need a separate JDK install if you let IntelliJ download it here.
3. Build the JAR. Open the Gradle tool window (the elephant icon on the right edge), expand Tasks > build, and double-click jar. Or run ./gradlew jar in a terminal at the project root. Gradle writes the file to build/libs/extension-template-project.jar.
4. Load it into Burp. Go to Extensions > Installed and click Add. Under Extension details, click Select file, choose the JAR you built, and click Open, then Next, then Close. Finally, tick the checkbox in the Auto-reload column for your extension so Burp reloads it every time you rebuild.
If the extension appears in the list with no errors, you’re ready. The main file is src/main/java/Extension.java, and its initialize(...) method is where this exercise begins.
Demo target
No Web Security Academy lab targets this format, so this workshop includes a small demo server that returns minified JSON: exactly what your tab handles.
It’s a single file with no build step or dependencies, and serves on http://localhost:8889. See the JSON demo server page for how to run it and the full list of endpoints.
To route traffic through Burp, click the browser icon in the top-right of Burp to open Burp’s browser, then go to http://localhost:8889/. You can also send its /api/* endpoints from Repeater. Any endpoint that returns JSON works: a Web Security Academy lab API response or a public API. The demo server gives you a reliable, offline option.
New to this? What you'll have open, and why
You’ll move between a few windows as you work. Arrange them once so you’re not hunting for them mid-exercise:
- IntelliJ: where you write the code and build the JAR.
- Burp > Extensions > Output: where your
logToOutputlines and any errors appear. Keep it open; it’s your first stop when something doesn’t work. - Burp’s message editor: open any response in Proxy > HTTP history or Repeater. Your new JSON tab shows here, next to Raw, Pretty, and Hex.
- A terminal: runs the demo server.
- Burp’s browser: the icon in the top-right of Burp. Use it to reach the demo server so its traffic flows through Burp.
The flow is always the same: edit in IntelliJ, build, let Burp reload, then look at Output or the message editor to see the result.
The provider and the editor
The structure you’ll build is a provider plus an editor:
- A provider is a factory Burp calls to create editor instances.
- An editor is the actual tab: it decides when to show, holds the UI component, and renders the message.
Each is a class of its own, because each has a single job: the provider creates editors, and the editor renders one message. Splitting them means you can change how the tab renders without touching how Burp obtains it. See Working with classes for how to add a class and the reasoning behind splitting your code.
How to approach it
Never coded before? The Java you need, in one place
An extension is a full Java program, but you only write a handful of small pieces. Here is the whole vocabulary they use, and it’s all you need to follow this exercise.
- Statement and comment. Each instruction ends with a semicolon (
;). Anything after//is a comment: a note for you that Java ignores. - Class and file. A class is a named bundle of code. Java keeps each public class in its own file named after it, so
JsonEditorProviderlives inJsonEditorProvider.java. This exercise has you create two classes, so two new files. - Object and method. An object is one real thing built from a class. A method is an action you call on it with a dot and parentheses:
montoyaApi.userInterface()asks the api for its user-interface area. Some methods take an input inside the parentheses; some take none. - Field. A value an object keeps for its whole life, declared at the top of the class. You’ll store the
apiin a field so every method in the class can reach it. - Interface. A checklist of methods Burp promises to call. Your class says
implements SomeInterfaceand provides a body for each method on the list; Burp then calls them when it needs to. IntelliJ can write the empty bodies for you (Step 3 shows how). import. Each file names the types it uses inimportlines at the top. IntelliJ adds these for you when you press ⌥Enter (Alt+Enter) on a name it has underlined in red.
The rest is a loop you’ll repeat: edit the code, build the JAR, and Burp picks up the change (Steps 4 and 5). If a line ever looks like a wall, come back here.
Step 1: Understand the entry point
Open the template in IntelliJ. The class implementing BurpExtension has one method, initialize(MontoyaApi montoyaApi), called once on load. Everything you register comes from the montoyaApi object, here montoyaApi.userInterface().
Tip: For more on this single entry point, see Programming Concepts: The MontoyaApi entry point.
New to this? Walk me through the entry point
Every extension is a class that implements BurpExtension. That interface has one method, initialize(MontoyaApi montoyaApi), and Burp calls it once, automatically, when your extension loads. You never call it yourself; you just fill in its body.
The montoyaApi argument is your door to everything Burp exposes:
montoyaApi.userInterface()reaches the UI, where you register tabs. You’ll use this one here.montoyaApi.logging()reaches the Output console.montoyaApi.http(),montoyaApi.scanner(), and the rest reach the other areas.
So the whole exercise is: build your provider and editor classes, then, inside initialize, call montoyaApi.userInterface() to register them.
Show the starting point
import burp.api.montoya.BurpExtension;
import burp.api.montoya.MontoyaApi;
public class Extension implements BurpExtension {
@Override
public void initialize(MontoyaApi montoyaApi) {
montoyaApi.extension().setName("My Extension");
// TODO Add your code here
}
}
Step 2: Create the provider
Add a class JsonEditorProvider implementing HttpResponseEditorProvider. A new class means a new file, so create JsonEditorProvider.java in src/main/java/, next to Extension.java: select that folder and press Alt+Insert (⌘N on macOS) > Java Class (see IntelliJ shortcuts). Its one job: return a fresh editor instance each time Burp opens a message editor. Keep the api so you can pass it to the editors you create.
Tip: On the class and the stored
apifield, see Programming Concepts: Classes and the one-file rule and Constructors and fields.
New to this? Walk me through creating the class
Create the file in IntelliJ:
- In the Project tool window on the left, expand the tree to
src>main>java. - Right-click the
javafolder and choose New > Java Class (or select the folder and press ⌘N on macOS, Alt+Insert on Windows/Linux). - Type
JsonEditorProviderand press Enter. IntelliJ createsJsonEditorProvider.javawith the class declaration ready.
Java requires each public class to live in a file named after it, which is why a new class always means a new file. Put it in src/main/java/, next to Extension.java, with no package line.
Make it a provider: add implements HttpResponseEditorProvider after the class name. If IntelliJ underlines a name in red, put the caret on it and press ⌥Enter (Alt+Enter) to import the type.
What the constructor and field are for: the provider needs the api later, so it stores it when it’s built.
private final MontoyaApi api;is a field: a value the object keeps for its lifetime.public JsonEditorProvider(MontoyaApi api) { this.api = api; }is the constructor: it runs once, when Burp creates the object, and copies the passed-inapiinto the field.this.apiis the field;apiis the argument.finalmeans you set it once and never change it.
From then on, any method in the class can use api.
Solution: `JsonEditorProvider.java`
import burp.api.montoya.ui.editor.extension.EditorCreationContext;
import burp.api.montoya.ui.editor.extension.HttpResponseEditorProvider;
import burp.api.montoya.ui.editor.extension.ExtensionProvidedHttpResponseEditor;
import burp.api.montoya.MontoyaApi;
public class JsonEditorProvider implements HttpResponseEditorProvider {
private final MontoyaApi api;
public JsonEditorProvider(MontoyaApi api) {
this.api = api;
}
@Override
public ExtensionProvidedHttpResponseEditor provideHttpResponseEditor(EditorCreationContext context) {
return new JsonResponseEditor(api);
}
}
This is a factory. Every time Burp opens a message editor, it calls provideHttpResponseEditor() to get a fresh editor instance.
Step 3: Create the editor
This is where the work happens. Add a class JsonResponseEditor implementing ExtensionProvidedHttpResponseEditor. The interface asks you to implement several methods. Let IntelliJ stub them all at once: press Alt+Enter on the class name and select Implement methods (see Implementing an interface, and Programming Concepts: Interfaces and @Override). Then think about what each is for before you look at the code:
New to this? Walk me through stubbing the methods
An interface is a contract: a list of methods Burp promises to call. Your class declares implements ExtensionProvidedHttpResponseEditor and must supply a body for every method the interface names, or it won’t compile.
Let IntelliJ write the empty method bodies for you:
- Type the declaration:
public class JsonResponseEditor implements ExtensionProvidedHttpResponseEditor {. IntelliJ underlines the class name in red because the required methods are missing. - Put the caret on the class name and press ⌥Enter (Alt+Enter), then choose Implement methods. (The direct shortcut is Ctrl+I, the Control key on macOS too.)
- In the dialog, select every method and click OK.
IntelliJ inserts a stub for each, already marked @Override. That annotation tells the compiler to check the method against the interface, so a misspelled name becomes an error instead of a method Burp silently never calls.
Now you fill in each stub, using the list below to decide what each one should do.
isEnabledFor(...): should the tab show for this message? Returntrueonly for JSON responses.setRequestResponse(...): Burp hands you the message; store the response and render it into your component.getResponse(): hand the (possibly edited) response back to Burp. Read-only here, so return the stored response unchanged.caption(): the tab label ("JSON").uiComponent(): the Swing component the tab displays.selectedData()/isModified(): selection support and whether the user edited anything (read-only here).
The rendering itself is a string transform: a small indentation pass over the body.
Hint: guarding and enabling
Both isEnabledFor and setRequestResponse must cope with a null response. For the enable check, api.utilities().jsonUtils().isValidJson(...) tests whether the body parses as JSON, which is more reliable than trusting the Content-Type header. Store the response in a field in setRequestResponse so the other methods can reach it.
Solution: `JsonResponseEditor.java`
import burp.api.montoya.MontoyaApi;
import burp.api.montoya.core.ByteArray;
import burp.api.montoya.http.message.HttpRequestResponse;
import burp.api.montoya.http.message.responses.HttpResponse;
import burp.api.montoya.ui.Selection;
import burp.api.montoya.ui.editor.extension.ExtensionProvidedHttpResponseEditor;
import javax.swing.*;
import java.awt.*;
public class JsonResponseEditor implements ExtensionProvidedHttpResponseEditor {
private final MontoyaApi api;
private final JTextArea textArea;
private HttpResponse currentResponse;
public JsonResponseEditor(MontoyaApi api) {
this.api = api;
this.textArea = new JTextArea();
this.textArea.setEditable(false);
this.textArea.setFont(new Font("Monospaced", Font.PLAIN, 12));
this.textArea.setLineWrap(true);
this.textArea.setWrapStyleWord(true);
}
@Override
public void setRequestResponse(HttpRequestResponse requestResponse) {
this.currentResponse = requestResponse.response();
if (currentResponse == null) {
textArea.setText("");
return;
}
String body = currentResponse.bodyToString();
textArea.setText(prettyPrintJson(body));
textArea.setCaretPosition(0); // scroll to top
}
@Override
public HttpResponse getResponse() {
return currentResponse;
}
@Override
public boolean isEnabledFor(HttpRequestResponse requestResponse) {
HttpResponse response = requestResponse.response();
if (response == null) return false;
return api.utilities().jsonUtils().isValidJson(response.bodyToString());
}
@Override
public String caption() {
return "JSON";
}
@Override
public Component uiComponent() {
return new JScrollPane(textArea);
}
@Override
public Selection selectedData() {
// Return the selected text as a ByteArray, or null if nothing selected
String selected = textArea.getSelectedText();
if (selected == null) return null;
return Selection.selection(ByteArray.byteArray(selected.getBytes()));
}
@Override
public boolean isModified() {
return false; // this editor is read-only
}
private String prettyPrintJson(String raw) {
// A simple indentation pass. For production use, add a JSON library to build.gradle
StringBuilder result = new StringBuilder();
int indent = 0;
boolean inString = false;
for (int i = 0; i < raw.length(); i++) {
char c = raw.charAt(i);
if (c == '"' && (i == 0 || raw.charAt(i - 1) != '\\')) {
inString = !inString;
result.append(c);
} else if (inString) {
result.append(c);
} else if (c == '{' || c == '[') {
result.append(c);
result.append('\n');
indent++;
result.append(" ".repeat(indent));
} else if (c == '}' || c == ']') {
result.append('\n');
indent--;
result.append(" ".repeat(indent));
result.append(c);
} else if (c == ',') {
result.append(c);
result.append('\n');
result.append(" ".repeat(indent));
} else if (c == ':') {
result.append(": ");
} else if (c != ' ' && c != '\n' && c != '\r' && c != '\t') {
result.append(c);
}
}
return result.toString();
}
}
The prettyPrintJson pass has no dependencies. For production, add a JSON parsing library to build.gradle and parse properly.
Tip: When IntelliJ flags a line in red, put the caret on it and press Alt+Enter for the context-action menu: it offers the relevant fix, whether that’s importing a missing class, stubbing an interface method, or creating a symbol. To fix every import at once, run Add or optimize imports. See IntelliJ shortcuts.
Step 4: Register the provider
Back in initialize(), register your provider so Burp knows about the tab. Give the extension a name and log a line so you can confirm it loaded.
Solution
@Override
public void initialize(MontoyaApi montoyaApi) {
montoyaApi.extension().setName("JSON Pretty Printer");
montoyaApi.logging().logToOutput("JSON Pretty Printer loaded.");
montoyaApi.userInterface().registerHttpResponseEditorProvider(new JsonEditorProvider(montoyaApi));
}
Step 5: Build, reload, and test
Run ./gradlew jar. With auto-reload enabled, Burp reloads the extension for you. Check Extensions > Output for JSON Pretty Printer loaded.
New to this? Walk me through building and reloading
Build the JAR:
- In IntelliJ, open the Gradle tool window (the elephant icon on the right edge), expand Tasks > build, and double-click jar. Or, in a terminal at the project root, run
./gradlew jar. - Watch for BUILD SUCCESSFUL. If the build fails, the error names the file and line to fix.
Reload into Burp:
- With auto-reload on, Burp reloads the extension for you the moment the JAR changes. There’s nothing more to do.
- If you didn’t enable it: go to Extensions > Installed and tick the checkbox in the Auto-reload column for your extension. To force a single reload instead, hold Ctrl (Cmd on macOS) and click the Loaded checkbox.
Confirm it loaded: open Extensions > Output. You should see JSON Pretty Printer loaded. there. That’s the log line from initialize, so seeing it means your code ran.
Now test it:
- Start the JSON demo server.
- Click the browser icon in the top-right of Burp to open Burp’s browser, then go to http://localhost:8889/.
- Open one of the
/api/*responses in the message editor.
You should see a JSON tab alongside Raw, Pretty, and Hex. Click it: the body appears indented. The /api/not-json endpoint is a good negative test: your tab should not appear there.
The tab doesn't appear?
Check that isEnabledFor() is returning true for your response. Add a debug line and watch Extensions > Output:
api.logging().logToOutput("isEnabledFor: valid JSON = "
+ api.utilities().jsonUtils().isValidJson(response.bodyToString()));
Check your work
- The JSON tab appears for JSON responses and is absent for others, such as HTML or images.
- The body renders indented and readable; switching rows updates it.
- No exceptions in Extensions > Output.
The complete extension
Every file in its finished state. These files go in src/main/java/ in the starter project: Extension.java (replacing the template’s), plus the provider and the editor.
`Extension.java`
import burp.api.montoya.BurpExtension;
import burp.api.montoya.MontoyaApi;
public class Extension implements BurpExtension {
@Override
public void initialize(MontoyaApi montoyaApi) {
montoyaApi.extension().setName("JSON Pretty Printer");
montoyaApi.logging().logToOutput("JSON Pretty Printer loaded.");
montoyaApi.userInterface().registerHttpResponseEditorProvider(new JsonEditorProvider(montoyaApi));
}
}
`JsonEditorProvider.java`
import burp.api.montoya.ui.editor.extension.EditorCreationContext;
import burp.api.montoya.ui.editor.extension.HttpResponseEditorProvider;
import burp.api.montoya.ui.editor.extension.ExtensionProvidedHttpResponseEditor;
import burp.api.montoya.MontoyaApi;
public class JsonEditorProvider implements HttpResponseEditorProvider {
private final MontoyaApi api;
public JsonEditorProvider(MontoyaApi api) {
this.api = api;
}
@Override
public ExtensionProvidedHttpResponseEditor provideHttpResponseEditor(EditorCreationContext context) {
return new JsonResponseEditor(api);
}
}
`JsonResponseEditor.java`
import burp.api.montoya.MontoyaApi;
import burp.api.montoya.core.ByteArray;
import burp.api.montoya.http.message.HttpRequestResponse;
import burp.api.montoya.http.message.responses.HttpResponse;
import burp.api.montoya.ui.Selection;
import burp.api.montoya.ui.editor.extension.ExtensionProvidedHttpResponseEditor;
import javax.swing.*;
import java.awt.*;
public class JsonResponseEditor implements ExtensionProvidedHttpResponseEditor {
private final MontoyaApi api;
private final JTextArea textArea;
private HttpResponse currentResponse;
public JsonResponseEditor(MontoyaApi api) {
this.api = api;
this.textArea = new JTextArea();
this.textArea.setEditable(false);
this.textArea.setFont(new Font("Monospaced", Font.PLAIN, 12));
this.textArea.setLineWrap(true);
this.textArea.setWrapStyleWord(true);
}
@Override
public void setRequestResponse(HttpRequestResponse requestResponse) {
this.currentResponse = requestResponse.response();
if (currentResponse == null) {
textArea.setText("");
return;
}
String body = currentResponse.bodyToString();
textArea.setText(prettyPrintJson(body));
textArea.setCaretPosition(0); // scroll to top
}
@Override
public HttpResponse getResponse() {
return currentResponse;
}
@Override
public boolean isEnabledFor(HttpRequestResponse requestResponse) {
HttpResponse response = requestResponse.response();
if (response == null) return false;
return api.utilities().jsonUtils().isValidJson(response.bodyToString());
}
@Override
public String caption() {
return "JSON";
}
@Override
public Component uiComponent() {
return new JScrollPane(textArea);
}
@Override
public Selection selectedData() {
// Return the selected text as a ByteArray, or null if nothing selected
String selected = textArea.getSelectedText();
if (selected == null) return null;
return Selection.selection(ByteArray.byteArray(selected.getBytes()));
}
@Override
public boolean isModified() {
return false; // this editor is read-only
}
private String prettyPrintJson(String raw) {
// A simple indentation pass. For production use, add a JSON library to build.gradle
StringBuilder result = new StringBuilder();
int indent = 0;
boolean inString = false;
for (int i = 0; i < raw.length(); i++) {
char c = raw.charAt(i);
if (c == '"' && (i == 0 || raw.charAt(i - 1) != '\\')) {
inString = !inString;
result.append(c);
} else if (inString) {
result.append(c);
} else if (c == '{' || c == '[') {
result.append(c);
result.append('\n');
indent++;
result.append(" ".repeat(indent));
} else if (c == '}' || c == ']') {
result.append('\n');
indent--;
result.append(" ".repeat(indent));
result.append(c);
} else if (c == ',') {
result.append(c);
result.append('\n');
result.append(" ".repeat(indent));
} else if (c == ':') {
result.append(": ");
} else if (c != ' ' && c != '\n' && c != '\r' && c != '\t') {
result.append(c);
}
}
return result.toString();
}
}
Taking it further
Decode a custom encoding
If the application uses a proprietary format, such as Base64-wrapped protobuf or a custom binary format, you need your own decoder. Replace prettyPrintJson() with it and display the decoded output. Point isEnabledFor() at the marker for your format, such as a header or path, then replace the rendering.
Solution
@Override
public void setRequestResponse(HttpRequestResponse requestResponse) {
this.currentResponse = requestResponse.response();
if (currentResponse == null) {
textArea.setText("");
return;
}
String body = currentResponse.bodyToString();
try {
// Example: the body is Base64-wrapped, so decode it and show the plain text
byte[] decoded = java.util.Base64.getDecoder().decode(body.trim());
textArea.setText(new String(decoded));
} catch (IllegalArgumentException e) {
textArea.setText(body); // not valid Base64, so fall back to the raw body
}
textArea.setCaretPosition(0);
}
Use Burp's own editor
The base exercise uses a plain JTextArea to show that uiComponent() accepts any Swing component you build. To match Burp’s own editor instead, use api.userInterface().createRawEditor(...). You get Burp’s search bar (Ctrl+F), theme and dark-mode support, and safe handling of non-printable bytes.
Three components fit this slot:
- For a plain component you fully control, use
JTextArea. - For Burp’s native look and behavior, use
RawEditor. - For syntax coloring you configure yourself, use
RSyntaxTextArea(below).
Note: Unlike the
RSyntaxTextArearoute,RawEditoris part of the Montoya API, so there’s nobuild.gradle.ktschange and nothing to bundle.EditorOptions.READ_ONLYmakes Burp enforce read-only, so you don’t callsetEditable(false).
Solution
Swap the JTextArea field for a RawEditor. The rest of the class (isEnabledFor, caption, prettyPrintJson) is unchanged:
import burp.api.montoya.core.ByteArray;
import burp.api.montoya.ui.Selection;
import burp.api.montoya.ui.editor.EditorOptions;
import burp.api.montoya.ui.editor.RawEditor;
private final RawEditor editor;
public JsonResponseEditor(MontoyaApi api) {
this.api = api;
this.editor = api.userInterface().createRawEditor(EditorOptions.READ_ONLY);
}
@Override
public void setRequestResponse(HttpRequestResponse requestResponse) {
this.currentResponse = requestResponse.response();
if (currentResponse == null) {
editor.setContents(ByteArray.byteArray(""));
return;
}
editor.setContents(ByteArray.byteArray(prettyPrintJson(currentResponse.bodyToString())));
}
@Override
public Component uiComponent() {
return editor.uiComponent();
}
@Override
public Selection selectedData() {
return editor.selection().orElse(null); // let the editor report the selection
}
@Override
public boolean isModified() {
return editor.isModified(); // always false while READ_ONLY, but delegate anyway
}
RawEditor includes its own scroll pane, so uiComponent() returns it directly. It matches Burp’s fonts and theme, so there’s no font or wrap setup. WRAP_LINES and SHOW_NON_PRINTABLE_CHARACTERS are the other EditorOptions.
Add syntax highlighting
Swap JTextArea for a syntax-highlighting component from a library added to build.gradle. RSyntaxTextArea is a drop-in JTextArea subclass.
Solution
// build.gradle.kts: Burp loads a single JAR, so the dependency must be bundled inside it.
// The starter project's jar task already packs the runtime classpath in, so implementation is enough.
dependencies {
compileOnly("net.portswigger.burp.extensions:montoya-api:2026.4")
implementation("com.fifesoft:rsyntaxtextarea:3.4.1")
}
Tip: After editing
build.gradle.kts, refresh Gradle so IntelliJ fetches the library. Open the Gradle tool window (the elephant icon on the right edge) and click the reload icon (the circular arrows) at the top of it. Until you sync, theorg.fife...imports stay unresolved in red.
import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
import org.fife.ui.rsyntaxtextarea.SyntaxConstants;
import org.fife.ui.rtextarea.RTextScrollPane;
private final RSyntaxTextArea textArea;
public JsonResponseEditor(MontoyaApi api) {
this.api = api;
this.textArea = new RSyntaxTextArea();
this.textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JSON);
this.textArea.setEditable(false);
this.textArea.setCodeFoldingEnabled(true);
}
@Override
public Component uiComponent() {
return new RTextScrollPane(textArea); // scroll pane with a gutter and folding controls
}
Add a request tab too
Register an HttpRequestEditorProvider alongside the response provider. This follows the response-editor structure with different interface names: HttpRequestEditorProvider / ExtensionProvidedHttpRequestEditor.
Solution
import burp.api.montoya.MontoyaApi;
import burp.api.montoya.ui.editor.extension.EditorCreationContext;
import burp.api.montoya.ui.editor.extension.ExtensionProvidedHttpRequestEditor;
import burp.api.montoya.ui.editor.extension.HttpRequestEditorProvider;
public class JsonRequestEditorProvider implements HttpRequestEditorProvider {
private final MontoyaApi api;
public JsonRequestEditorProvider(MontoyaApi api) {
this.api = api;
}
@Override
public ExtensionProvidedHttpRequestEditor provideHttpRequestEditor(EditorCreationContext context) {
return new JsonRequestEditor(api);
}
}
The editor mirrors JsonResponseEditor method-for-method, reading requestResponse.request() instead of .response(). The one rename in the required method set is getResponse() → getRequest():
@Override
public HttpRequest getRequest() {
return currentRequest; // read-only: hand the request back unchanged
}
Register it next to the response provider:
montoyaApi.userInterface().registerHttpRequestEditorProvider(new JsonRequestEditorProvider(montoyaApi));
Make it editable
Set textArea.setEditable(true), track changes in isModified(), and return the edited content from getResponse() (the read-only stub from Step 3). Store what you rendered so isModified() has something to compare against.
Solution
private String renderedText = "";
@Override
public void setRequestResponse(HttpRequestResponse requestResponse) {
this.currentResponse = requestResponse.response();
renderedText = currentResponse == null ? "" : prettyPrintJson(currentResponse.bodyToString());
textArea.setEditable(true);
textArea.setText(renderedText);
textArea.setCaretPosition(0);
}
@Override
public boolean isModified() {
return !textArea.getText().equals(renderedText);
}
@Override
public HttpResponse getResponse() {
if (currentResponse == null) return null;
// Write the edited text back as the new body
return currentResponse.withBody(textArea.getText());
}
Because your editor reformats the body on display, getResponse() writes the pretty-printed text back. If Burp must see the original bytes when untouched, keep the raw body in a field and return currentResponse unchanged while isModified() is false.
Extract fields instead of reformatting
The same tab pattern makes a good field extractor: instead of pretty-printing the whole body, pull out only the values you care about. Burp’s built-in JsonUtils reads them by location, so you need no parser and no dependency.
Solution
import burp.api.montoya.utilities.json.JsonUtils;
// In setRequestResponse(), once you have the body string:
JsonUtils json = api.utilities().jsonUtils();
String body = currentResponse.bodyToString();
String summary = "user: " + json.readString(body, "data.user.email") + "\n"
+ "token: " + json.readString(body, "data.session.token");
textArea.setText(summary);
Locations are period-delimited, with [n] for array indices ("orders.[0].id"). The readString, readLong, readDouble, and readBoolean methods return null when the location is absent or the wrong type, so guard any value you display. read() hands back a nested object or array as a JSON string, and isValidJson() gates the whole thing: the same call the enable check uses.