Transform JMeter JDBC Request Output to JSON: A Step‑by‑Step Guide

This article explains how to modify JMeter's source code so that the JDBC Request sampler returns results in a clean JSON format, covering environment setup, code changes, building the custom JAR, integration, and the resulting improvements in readability and automation.

Zhongtong Tech
Zhongtong Tech
Zhongtong Tech
Transform JMeter JDBC Request Output to JSON: A Step‑by‑Step Guide

Background

When using JMeter for testing, the JDBC Request sampler returns results as an unstructured, tab‑separated text table, making it difficult to locate field values, especially when dealing with tables that have dozens of columns.

The goal is to modify JMeter's source so that the sampler returns a simple, readable, and easily parsable JSON array.

Source Code Modification Process

1. Import JMeter source into IDEA

Download apache-jmeter-5.4.1_src.zip from the official site, unzip it, and note that the extracted files do not contain the Eclipse projects or an Ant build.xml; JMeter 5.4 uses Gradle.

Open IntelliJ IDEA, choose File → Open , select the parent directory of the bin folder, and let IDEA detect the Gradle build script. Click Import Gradle Project to let IDEA download required dependencies.

Run JMeter from the NewDriver class or execute the runGui script under development to verify the IDE setup.

2. Modify JDBC Request return handling

The processing logic resides in org.apache.jmeter.protocol.jdbc.AbstractJDBCTestElement. Replace the original getStringFromResultSet and processRow methods with the following implementations that build a JSON array:

private String getStringFromResultSet(ResultSet rs) throws SQLException, UnsupportedEncodingException { ... }
private int processRow(ResultSet rs, ResultSetMetaData meta, StringBuilder sb, int numColumns, JMeterVariables jmvars, String[] varNames, List<Map<String, Object>> results, int currentIterationIndex) throws SQLException, UnsupportedEncodingException { ... }

The new code constructs a JSON string, stores results in JMeter variables, and handles various SQL types appropriately.

3. Build and integrate the custom JAR

After code changes, run the Gradle build in IDEA; the compiled JAR appears in jmeter/lib/ext as jmeter_jdbc.jar.

Copy this JAR into the local JMeter installation’s lib/ext directory, overwriting the original JDBC sampler JAR (backup the original first).

Effect After Modification

Running the locally integrated JMeter now shows JDBC Request results as a JSON array, which can be easily processed with a JSON Extractor or external libraries such as FastJSON.

Screenshot of the original messy output (removed for brevity).

Screenshot of the JSON output in the View Results Tree.

Example of using a JSON Extractor to fetch specific fields.

Example of a post‑processor that parses the JSON with FastJSON to obtain desired values.

Conclusion

The source‑code modification resolves the cluttered display issue of the JDBC Sampler, delivering a JSON‑formatted result that mirrors typical API responses. This greatly improves both manual inspection and automated validation in performance testing workflows.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavaPerformance TestingJSONJMeterJDBCTesting toolsSource Code Modification
Zhongtong Tech
Written by

Zhongtong Tech

Integrating industry and information for digital efficiency, advancing Zhongtong Express's high-quality development through digitalization. This is the public channel of Zhongtong's tech team, delivering internal tech insights, product news, job openings, and event updates. Stay tuned!

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.