Runtime ModulesTransformation

JSON Minification

Minify embedded JSON in requests by stripping whitespace and indentation for 20–45% token reduction while preserving standard JSON.

JSON Minification automatically detects all embedded JSON objects and arrays within request messages and replaces them with their compact, minified equivalents. By removing unnecessary whitespace, indentation, and newlines, JSON Minification achieves 20–45% prompt token reduction on formatted or pretty-printed JSON payloads while guaranteeing 100% syntactically valid standard JSON.

This module has no configuration — it scans all text fields in every message and replaces each detected JSON blob with its compact representation automatically.


Stage

StageBehavior
PRE onlyScans all message text fields for embedded JSON and minifies each detected blob before forwarding to the LLM

How It Works

Formatted JSON generated by databases, APIs, code formatters, and RAG pipelines frequently includes multi-space indentation and newline characters that consume valuable context tokens without conveying extra information.

JSON Minification:

  • Strips all unnecessary whitespace around delimiters (using compact "," and ":" separators).
  • Preserves UTF-8 characters without escaping (ensure_ascii=False), preventing token-heavy \uXXXX sequences.
  • Retains 100% standard JSON syntax — zero format changes or alternative syntaxes introduced.

Example

Formatted JSON (original, ~115 tokens):

{
  "status": "success",
  "data": {
    "user_id": 10482,
    "name": "Jane Doe",
    "roles": [
      "engineer",
      "maintainer"
    ]
  },
  "cache_hit": true
}

Minified JSON (compact, ~72 tokens):

{"status":"success","data":{"user_id":10482,"name":"Jane Doe","roles":["engineer","maintainer"]},"cache_hit":true}

The payload delivers the identical data model to the LLM in significantly fewer tokens, fitting more context into the window and reducing inference costs.


JSON Minification vs. JSON to TOON

FeatureJSON MinificationJSON to TOON
Output SyntaxStandard JSON ({...}, [...])TOON (Indentation & CSV-style tables)
Token Savings20–45%30–60%
LLM StrictnessCompatible with models or prompts that mandate strict standard JSON syntaxIdeal when maximum token reduction is desired and models support structured text
ConfigurationNoneNone

Configuration

This module has no configuration parameters. It operates automatically on all valid JSON found within request messages.


Conversion Behavior

  • All message fields are scanned — content, system, developer messages, tool responses, and multi-part content arrays.
  • In-place replacement — Embedded JSON surrounded by normal prose is cleanly minified in place without altering surrounding text.
  • Idempotent — Already-minified JSON blobs are detected and left untouched without unnecessary re-serialization.
  • Non-JSON tags and markdown links are preserved — Plain-text tags (such as [User]:, [Assistant]:, [TODO]), markdown links ([text](url)), and template variables ({name}) are protected by structural pre-filtering and are never mistakenly parsed or mutated.
  • Invalid JSON is left unchanged — no errors are raised for malformed blobs.

Example Use Cases

  • RAG & Vector Retrieval: Embedding multi-record database rows or pretty-printed JSON payloads into prompt context.
  • Tool / Function Results: Compacting large JSON payloads returned by API tools before they enter subsequent conversation turns.
  • Cost Reduction with Standard JSON: Achieving immediate token savings across high-volume traffic without changing downstream JSON parsing logic or prompt expectations.

On this page