T3Toon 

Extension key

rrp_t3toon

Package name

rrp/t3-toon

Version

1.1

Language

en

Author

Rohan Parmar | Himanshu Ramavat

License

MIT License

Rendered

Mon, 12 Jan 2026 18:16:18 +0000


T3Toon — also known as Token-Optimized Object Notation — is a TYPO3-native AI data optimization library that transforms large JSON or PHP arrays into a compact, readable, and token-efficient format.

It's crafted for developers working with ChatGPT, Gemini, Claude, Mistral, or OpenAI APIs, helping you: Save tokens and reduce API costs Simplify complex prompt structures Improve AI response quality and context understanding Maintain human readability and reversibility


Introduction 

Introduction to the extension T3Toon, general information and features.

Quick start 

A quick introduction on how to install and use this extension.

Usage 

Learn how to use T3Toon for encoding and decoding data, token estimation, and analytics.

Reference 

In-depth reference about the API, services, and configuration options.

About T3Toon 

What is T3Toon? 

T3Toon (Token-Optimized Object Notation) is a compact, human-readable, and token-efficient data format designed specifically for AI and LLM integrations in TYPO3 CMS.

It transforms large JSON or PHP arrays into a format that:

  • Reduces token usage by up to 70% compared to JSON
  • Maintains human readability (YAML-like structure)
  • Preserves complete data structure and key order
  • Supports bidirectional conversion (JSON ⇄ TOON)

Use Cases 

T3Toon is perfect for:

  • AI Prompt Engineering: Compress structured data for LLMs (ChatGPT, Gemini, Claude, Mistral)
  • Token Optimization: Reduce token usage and API costs
  • Data Preprocessing: Streamline complex structured inputs
  • Logging & Debugging: Store compact, readable structured logs
  • Database Storage: Reduce JSON storage size while preserving structure
  • Developer Tools: Perfect for previews and compact dashboards

Why T3Toon? 

When working with AI APIs, every token counts. Traditional JSON format includes:

  • Redundant quotes around keys and string values
  • Verbose syntax (braces, brackets, commas)
  • Repeated structural markers

T3Toon eliminates this overhead while maintaining:

  • Complete data fidelity
  • Human readability
  • Easy parsing and conversion
  • Support for complex nested structures

Example Comparison 

JSON Format (7.7 KB,  1,930 tokens):

{
  "user": "ABC",
  "message": "Hello, how are you?",
  "tasks": [
    {"id": 1, "done": false},
    {"id": 2, "done": true}
  ]
}
Copied!

TOON Format (2.5 KB,  640 tokens):

user: ABC
message: Hello\, how are you?
tasks:
  items[2]{done,id}:
    false,1
    true,2
Copied!

Result:  67% size reduction and  66.8% fewer tokens while retaining complete data accuracy.

Key Features 

Bidirectional Conversion 

Convert between JSON and TOON format seamlessly:

  • JSON → TOON: Compress data for AI prompts
  • TOON → JSON: Restore original structure

Readable & Compact 

  • YAML-like structure that's human-friendly
  • Maintains readability while reducing size
  • Easy to edit and debug manually

Token-Efficient 

  • Save up to 70% tokens on every AI prompt
  • Reduces API costs significantly
  • Optimized for ChatGPT, Gemini, Claude, and Mistral models

Preserves Key Order 

  • Ensures deterministic data output
  • Maintains structure integrity
  • Critical for consistent AI responses

Built-in Analytics 

  • Measure token, byte, and compression performance
  • Compare JSON vs TOON metrics
  • Track optimization benefits

Complex Nested Array Support 

  • Fully supports deeply nested associative and indexed arrays
  • Handles multi-level structures
  • Preserves all structural information

AI & LLM Ready 

  • Optimized for modern AI models
  • Perfect for prompt engineering
  • Reduces context window usage

TYPO3 Integration 

  • Native TYPO3 extension
  • Follows TYPO3 coding standards
  • Dependency injection support
  • Service-based architecture

Quick start 

  1. Install this extension:

    composer require rrp/t3-toon
    Copied!
  2. Start using T3Toon:

    • Convert JSON to TOON format
    • Decode TOON back to arrays
    • Estimate tokens
  3. Configure (optional):

    • Adjust encoding settings
    • Customize compression behavior

Quick installation 

In a composer-based TYPO3 installation you can install the extension EXT:rrp_t3toon via composer:

composer require rrp/t3-toon
Copied!

In TYPO3 installations above version 11.5 the extension will be automatically installed. You do not have to activate it manually.

Requirements 

  • TYPO3 CMS 12.0.0 - 13.9.99
  • PHP 8.0 or higher

Update the database scheme 

Open your TYPO3 backend with system maintainer permissions.

In the module menu to the left navigate to Admin Tools > Maintenance, then click on Analyze database and create all.

Clear all caches 

In the same module Admin Tools > Maintenance you can also conveniently clear all caches by clicking the button Flush cache.

Verify Installation 

After installation, you can verify that the extension is loaded by checking the extension manager or by using the service in your code:

use RRP\T3Toon\Service\Toon;

// Test encoding
$data = ['test' => 'value'];
$toon = Toon::convert($data);
echo $toon; // Should output: test: value
Copied!

Quick usage 

Basic Encoding (JSON → TOON) 

Convert PHP arrays or JSON strings to TOON format:

use RRP\T3Toon\Service\Toon;

$data = [
    'user' => 'ABC',
    'message' => 'Hello, how are you?',
    'tasks' => [
        ['id' => 1, 'done' => false],
        ['id' => 2, 'done' => true],
    ],
];

$toon = Toon::convert($data);
echo $toon;
Copied!

Output:

user: ABC
message: Hello\, how are you?
tasks:
  items[2]{done,id}:
    false,1
    true,2
Copied!

Basic Decoding (TOON → JSON) 

Convert TOON format back to PHP arrays:

use RRP\T3Toon\Service\Toon;

$toon = <<<TOON
user: ABC
tasks:
  items[2]{id,done}:
    1,false
    2,true
TOON;

$data = Toon::decode($toon);
print_r($data);
Copied!

Output:

Array
(
    [user] => ABC
    [tasks] => Array
        (
            [0] => Array
                (
                    [id] => 1
                    [done] => false
                )
            [1] => Array
                (
                    [id] => 2
                    [done] => true
                )
        )
)
Copied!

Token Estimation 

Estimate the number of tokens in a TOON string:

use RRP\T3Toon\Service\Toon;

$toon = Toon::convert($data);
$stats = Toon::estimateTokens($toon);
print_r($stats);
Copied!

Output:

Array
(
    [words] => 20
    [chars] => 182
    [tokens_estimate] => 19
)
Copied!

Using Dependency Injection 

For better testability and TYPO3 integration, use dependency injection:

use RRP\T3Toon\Service\Toon;
use TYPO3\CMS\Core\Utility\GeneralUtility;

$toonService = GeneralUtility::makeInstance(Toon::class);
$toon = $toonService->convert($data);
$decoded = $toonService->decode($toon);
Copied!

Working with JSON Strings 

T3Toon automatically detects and handles JSON strings:

use RRP\T3Toon\Service\Toon;

$json = '{"user":"ABC","active":true}';
$toon = Toon::convert($json);
echo $toon;
Copied!

Output:

user: ABC
active: true
Copied!

Complex Nested Structures 

T3Toon handles deeply nested structures:

use RRP\T3Toon\Service\Toon;

$data = [
    'user' => [
        'id' => 101,
        'active' => true,
        'roles' => ['admin', 'editor'],
        'profile' => [
            'age' => 32,
            'location' => [
                'city' => 'ABC',
                'country' => 'India',
            ],
        ],
    ],
    'orders' => [
        [
            'order_id' => 'ORD-1001',
            'amount' => 1998,
            'status' => 'paid',
        ],
    ],
];

$toon = Toon::convert($data);
echo $toon;
Copied!

This structure remains human-readable, reversible, and compact, even with deep nesting.

Configuration 

T3Toon can be configured through the TYPO3 Extension Manager or by setting extension configuration.

Access Configuration 

Navigate to Admin Tools > Settings > Extension Configuration and select T3Toon – Token-Efficient Data Format for TYPO3 AI.

Configuration Options 

Escape Style 

Type

string

Default

backslash

Description

The style used for escaping special characters in TOON format.

Available options: * backslash - Use backslash escaping (e.g., Hello\, world)

Minimum Rows for Tabular Format 

Type

integer

Default

2

Description

Minimum number of rows required before converting arrays to tabular format.

When arrays have at least this many items with the same structure, they are converted to a more compact tabular format:

items[2]{id,done}:
  1,false
  2,true
Copied!

Maximum Preview Items 

Type

integer

Default

200

Description

Maximum number of items to preview in nested structures.

This prevents extremely large arrays from generating unreadable output.

Coerce Scalar Types 

Type

boolean

Default

1 (enabled)

Description

Automatically convert string representations of booleans and numbers

When enabled: ``"true"`` → ``true`` (boolean) "false"false (boolean) ``"123"`` → ``123`` (integer) "45.67"45.67 (float)

Programmatic Configuration 

You can also access configuration programmatically:

use RRP\T3Toon\Utility\ToonHelper;

$config = ToonHelper::getConfig();
// Returns:
// [
//     'escape_style' => 'backslash',
//     'min_rows_to_tabular' => 2,
//     'max_preview_items' => 200,
//     'coerce_scalar_types' => true,
// ]
Copied!

Service API Reference 

Main Service Class: Toon 

The main service class provides static and instance methods for converting between PHP arrays/JSON and TOON format.

Class: RRP\T3Toon\Service\Toon

Static Methods 

convert() 

Convert arbitrary input into TOON format.

Signature

static string convert(mixed $input)

Parameters
  • $input (mixed) - JSON string, array, or object
Returns

string - TOON representation

Throws

RRP\T3Toon\Exception\ToonEncodeException

use RRP\T3Toon\Service\Toon;

$data = ['key' => 'value'];
$toon = Toon::convert($data);
Copied!

encode() 

Encode arbitrary input into TOON format (alias for convert()).

Signature

static string encode(mixed $input)

Parameters
  • $input (mixed) - JSON string, array, or object
Returns

string - TOON representation

Throws

RRP\T3Toon\Exception\ToonEncodeException

use RRP\T3Toon\Service\Toon;

$toon = Toon::encode($data);
Copied!

decode() 

Decode a TOON string into an associative PHP array.

Signature

static array decode(string $toon)

Parameters
  • $toon (string) - TOON-formatted string
Returns

array - Decoded PHP array

Throws

RRP\T3Toon\Exception\ToonDecodeException

use RRP\T3Toon\Service\Toon;

$toon = "user: ABC\nactive: true";
$data = Toon::decode($toon);
Copied!

estimateTokens() 

Estimate the number of tokens in a TOON string.

Signature

static array estimateTokens(string $toon)

Parameters
  • $toon (string) - TOON-formatted string
Returns

array - Array with keys: ``words`` (int) - Word count chars (int) - Character count * tokens_estimate (int) - Estimated token count

use RRP\T3Toon\Service\Toon;

$stats = Toon::estimateTokens($toon);
// Returns: ['words' => 20, 'chars' => 182, 'tokens_estimate' => 19]
Copied!

Instance Methods 

The same methods are available as instance methods for dependency injection:

use RRP\T3Toon\Service\Toon;
use TYPO3\CMS\Core\Utility\GeneralUtility;

$toon = GeneralUtility::makeInstance(Toon::class);
$result = $toon->convert($data);
$decoded = $toon->decode($result);
$stats = $toon->estimateTokens($result);
Copied!

Internal Services 

ToonEncoder 

Class: RRP\T3Toon\Service\ToonEncoder

Handles conversion from PHP arrays/objects/JSON to TOON format.

Method

toToon(mixed $input): string

ToonDecoder 

Class: RRP\T3Toon\Service\ToonDecoder

Handles conversion from TOON format to PHP arrays.

Method

fromToon(string $toon): array

Utility Classes 

ToonHelper 

Class: RRP\T3Toon\Utility\ToonHelper

Provides configuration access and utility methods.

Method

static array getConfig() - Get extension configuration

Configuration Reference 

Extension Configuration 

The extension configuration is stored in the TYPO3 Extension Manager and can be accessed programmatically via ToonHelper::getConfig().

Configuration Array Structure 

[
    'escape_style' => 'backslash',        // string
    'min_rows_to_tabular' => 2,            // int
    'max_preview_items' => 200,            // int
    'coerce_scalar_types' => true,         // bool
]
Copied!

Accessing Configuration 

use RRP\T3Toon\Utility\ToonHelper;

$config = ToonHelper::getConfig();
$escapeStyle = $config['escape_style'];
Copied!

Configuration via Extension Manager 

Navigate to Admin Tools > Settings > Extension Configuration and select T3Toon – Token-Efficient Data Format for TYPO3 AI.

All configuration options are available through the Extension Manager interface.

Service Configuration 

The extension uses TYPO3's dependency injection container. Services are configured in Configuration/Services.yaml.

Default Service Configuration 

services:
  _defaults:
    autowire: true
    autoconfigure: true
    public: false

  RRP\T3Toon\:
    resource: '../Classes/*'
    exclude: '../Classes/Domain/Model/*'
Copied!

Custom Service Configuration 

You can override service configuration in your site package:

services:
  RRP\T3Toon\Service\ToonEncoder:
    arguments:
      $config:
        escape_style: 'custom'
        min_rows_to_tabular: 3
Copied!

Sitemap