Font Size:
Ask Joget AI

JSON Extractor

Introduction

The JSON Extractor enhancer strips prose, code fences, and commentary from an agent's response, leaving only valid JSON that downstream enhancers and decisions can reliably parse.

Note

Place JSON Extractor before any enhancer that expects JSON input, such as Store to Form Enhancer in JSON mode, Fill Form Enhancer, or Store to Agent Variable Enhancer in JSON Field mode. The order of enhancers on a task matters.

What it does

JSON Extractor rewrites the agent task's response with only the JSON content, discarding everything else. It runs two extraction strategies in sequence:

Pattern extraction scans the response for a JSON block and isolates it. This handles the most common cases: JSON wrapped in a code fence (```json ... ```), JSON embedded mid-paragraph, or a response that is already clean JSON.

LLM re-parse (when enabled) fires a follow-up call to the same LLM when pattern extraction finds no valid JSON. The LLM is given a prompt instructing it to reformat the response as a JSON object. This is a recovery mechanism for responses where the JSON is malformed or entirely absent from the text.

After extraction, the response content is replaced with the cleaned JSON string. All later enhancers and decisions on the same task see the cleaned version.

The Output Format prompt is the input-side counterpart: it instructs the LLM to produce JSON in the first place. JSON Extractor is the output-side safety net that cleans up when the instruction is not followed exactly.

When to use it

Use Store to Agent Variable when all of the following are true:

  • One task produces a value that a later task in the same agent needs.
  • You do not need the value to persist beyond the current agent run.
  • You want to avoid writing to a form or workflow variable just to pass data between tasks.

Typical scenarios include the following:

  • CRM: Staged Enrichment: Task 1 extracts a company name from an email. Task 2 uses that name to look up open opportunities. Store to Agent Variable passes the name between tasks.
  • HR: Multi-step Analysis: Task 1 classifies a leave request as routine or exceptional. Task 2 drafts a response tailored to the classification. The variable carries the classification forward.
  • Procurement: JSON Field Routing: Task 1 extracts invoice fields as JSON. Store to Agent Variable pulls the vendor name from the JSON and injects it into Task 2's prompt for a supplier check.
When not to use it

Get started

How to use it

To add the Store to Agent Variable enhancer:

  1. Locate the Store to Agent Variable element under the Enhancers section of the palette.
  2. Drag and drop the element into the Drop an enhancer to here section.

Configure Enhancer Properties

Always-visible fields

  • Variable Name: The agent variable that receives the value. Enter the exact name declared in the agent's Properties panel. Case-sensitive. This field is required.
  • Value Source: Whether to store the full response or extract a JSON field. Full Response (text) to store the whole output. JSON Field to extract one value from a JSON response.

JSON Field mode

This field appears only when Value Source is set to JSON Field:

  • JSON Field Path: The dot-notation path into the JSON object. A path such as order.id or status. Extracts the matching value from the JSON response.

Samples

JSON Field mode: extract an invoice number
Agent variable declared: inv_number

Task 1 output (after JSON Extractor runs first):
{"invoice_number": "INV-2024-001", "amount": 5000, "vendor": "Acme Corp"}

Store to Agent Variable settings:
  Variable Name: inv_number
  Value Source: JSON Field
  JSON Field Path: invoice_number

Result: inv_number = "INV-2024-001"

Task 2 uses the Agent Variable prompt referencing inv_number
to inject "INV-2024-001" into its system prompt automatically.
JSON
 

Best Practices

  • Declare the variable first. If the variable name does not match a declared variable, the value is written to an undeclared key, and the Agent Variables prompt will not inject it correctly.
  • JSON Field path is case-sensitive. Invoice_Number and invoice_number are different paths. Match the exact key casing the LLM returns.
  • Pair with JSON Extractor for chatty models. If the LLM wraps the JSON in prose or code fences, place JSON Extractor Enhancer before this enhancer so JSON Field mode receives a clean object.
  • Variables are run-scoped. The value does not carry over to a second invocation of the same agent. For persistent storage, follow up with Store to Form Enhancer.
  • The Set Agent Variable Tool covers the same write but runs during a task (in the Tools phase) rather than after it. Use the tool when the variable must be set mid-task; use this enhancer when you want to capture the final response.
Created by Debanraj Ravindran Last modified by Debanraj Ravindran on Jul 11, 2026