How to extract JSON values in JMeter

API load tests often need a value produced by one response before a later request can run. The JMeter JSON Extractor captures fields from a JSON sampler response and stores them as variables, which keeps tokens, order IDs, session IDs, and generated resource IDs moving through the same virtual user flow.

The extractor is a post-processor, so it belongs under the sampler that receives the JSON payload. Its variable names, JSONPath expressions, default values, and match numbers are semicolon-separated lists; each position must describe the same captured value when more than one field is extracted.

Start with one value and a visible default while building the test. A downstream sampler or debug sampler should prove the variable before a larger run, because an unresolved variable can turn into a literal variable reference or a default value that hides a broken correlation.

Steps to extract a JSON value with a JMeter JSON Extractor:

  1. Open the .jmx test plan in the JMeter GUI.
  2. Select the sampler that returns the JSON response.
  3. Add the extractor from Add → Post Processors → JSON Extractor.
  4. Name the extractor for the value it captures.
    Name: Extract checkout CSRF token
  5. Keep Apply to set to Main sample only for a normal HTTP response.

    Use Sub-samples only, Main sample and sub-samples, or JMeter Variable Name to use only when the target JSON is in an embedded resource, generated child sample, or existing JMeter variable.

  6. Set Names of created variables to csrf_token.
  7. Set JSON Path Expressions to $.session.csrf.

    Test the expression against a representative response before saving the extractor when the JSON branch is nested, optional, or repeated.
    Tool: JSONPath Tester

  8. Set Match Numbers to 1.

    Use 0 only when a random match is acceptable. Use -1 only when every match should be stored as numbered variables such as csrf_token_1 and csrf_token_2.

  9. Set Default Values to TOKEN_NOT_FOUND.

    A visible default makes a missed path obvious during debugging. For multiple variables, keep the default-value list in the same semicolon-separated order as the variable names and JSONPath expressions.

  10. Leave Compute concatenation var cleared.

    Select it only when Match Numbers is -1 and a comma-separated value such as csrf_token_ALL is useful for the later sampler or debug output.

  11. Use the extracted variable in a later sampler.
    Name: csrf
    Value: ${csrf_token}
  12. Save the validation copy of the test plan.
    json-extractor-demo.jmx
  13. Run a one-user non-GUI smoke test.
    $ jmeter -n -t json-extractor-demo.jmx -l json-extractor-results.jtl -j jmeter.log
    Creating summariser <summary>
    Created the tree successfully using json-extractor-demo.jmx
    Starting standalone test @ 2026 Jun 30 01:36:38 GMT
    Waiting for possible Shutdown/StopTestNow/HeapDump/ThreadDump message on port 4445
    summary =      2 in 00:00:00 =    4.3/s Avg:   209 Min:    68 Max:   350 Err:     0 (0.00%)
    Tidying up ...
    ... end of run
  14. Check the result file for successful upstream and downstream samplers.
    $ cat json-extractor-results.jtl
    timeStamp,elapsed,label,responseCode,responseMessage,threadName,dataType,success,failureMessage,bytes,sentBytes,grpThreads,allThreads,URL,Latency,IdleTime,Connect
    1782783398612,350,GET checkout session,200,OK,Checkout correlation user 1-1,text,true,,73,0,1,1,null,0,0,0
    1782783398979,68,POST checkout confirmation,200,OK,Checkout correlation user 1-1,text,true,,26,0,1,1,null,0,0,0
  15. Check the downstream sampler or request log for the captured value.
    $ cat json-extractor.log
    csrf_token=token-abc-123
    posted_token=token-abc-123

    The extracted value and the posted value should match. If the value is TOKEN_NOT_FOUND, inspect the response body and JSONPath expression in a small debug run before increasing thread count.
    Related: How to add a Debug Sampler in JMeter