PHPackages                             jobmetric/laravel-toon - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. jobmetric/laravel-toon

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

jobmetric/laravel-toon
======================

Laravel integration for TOON format: encode/decode JSON data into a token-optimized notation for LLMs.

1.0.0(5mo ago)26267↑25%MITPHPPHP &gt;=8.0.1CI passing

Since Nov 17Pushed 4mo agoCompare

[ Source](https://github.com/jobmetric/laravel-toon)[ Packagist](https://packagist.org/packages/jobmetric/laravel-toon)[ Docs](https://doc.jobmetric.net/package/laravel-toon)[ RSS](/packages/jobmetric-laravel-toon/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (4)Versions (2)Used By (0)

[![Contributors](https://camo.githubusercontent.com/56034bfa8be0d1706b4639c26b4910af2953338df27be102066dac9e4affd455/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f636f6e7472696275746f72732f6a6f626d65747269632f6c61726176656c2d746f6f6e2e7376673f7374796c653d666f722d7468652d6261646765)](https://github.com/jobmetric/laravel-toon/graphs/contributors)[![Forks](https://camo.githubusercontent.com/0a0324897a69e91e22402a0c25cfec155964b12546ceeea92b4e2b21a8d15d20/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f666f726b732f6a6f626d65747269632f6c61726176656c2d746f6f6e2e7376673f7374796c653d666f722d7468652d6261646765266c6162656c3d466f726b)](https://github.com/jobmetric/laravel-toon/network/members)[![Stargazers](https://camo.githubusercontent.com/2b5a168067e540ed3c459b2c87deb08f2e2e1f3cf2d7ecf5e07b25ad3c84d081/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f6a6f626d65747269632f6c61726176656c2d746f6f6e2e7376673f7374796c653d666f722d7468652d6261646765)](https://github.com/jobmetric/laravel-toon/stargazers)[![MIT License](https://camo.githubusercontent.com/abc9425fab6afb02c173a384a637096df31810d207d67327463334897f071d5b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6a6f626d65747269632f6c61726176656c2d746f6f6e2e7376673f7374796c653d666f722d7468652d6261646765)](https://github.com/jobmetric/laravel-toon/blob/master/LICENCE.md)[![LinkedIn](https://camo.githubusercontent.com/eb590f47a3fca74584d18db8dd3e985ae3d786f50cd41b7530c3af3885da233c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f2d4c696e6b6564496e2d626c75652e7376673f7374796c653d666f722d7468652d6261646765266c6f676f3d6c696e6b6564696e26636f6c6f72423d353535)](https://linkedin.com/in/majidmohammadian)

Laravel Toon Converter (json to toon for LLMs)
==============================================

[](#laravel-toon-converter-json-to-toon-for-llms)

Laravel integration for TOON format: encode/decode JSON data into a token‑optimized notation for LLMs. This package provides first‑class TOON support in Laravel with spec‑conformant encoding/decoding, smart tabular formatting, safe key folding, and developer‑friendly APIs (Facade, helpers, DI).

Requirements
------------

[](#requirements)

- PHP &gt;= 8.0.1
- Laravel &gt;= 9.19
- Composer

Installation
------------

[](#installation)

Install via Composer:

```
composer require jobmetric/laravel-toon
```

The service provider is auto‑discovered. The `Toon` facade and global helpers are registered.

Configuration
-------------

[](#configuration)

Publish/override the `laravel-toon` config as needed. Available options (defaults in parentheses):

- `indent` (2): spaces per indent level (encoder/decoder)
- `delimiter` (','): array delimiter — one of `,`, `\t`, `|`
    - Non‑default delimiter appears in headers, e.g. `[3|]: 1|2|3` or `[2\t]{id\tname}:`
- `min_rows_tabular` (1): if list of uniform objects has ≥ this count, use tabular format
- `newline_final` (false): append trailing newline on encode
- `key_folding` ('off'): 'off' or 'safe' — fold single‑key chains into dotted path when safe
- `flatten_depth` (-1): max depth of folding (`-1` = unlimited)
- `folding_exclude` (\[\]): prefixes to opt‑out from folding
- `expand_paths` (false): expand dotted keys on decode (safe segments only)
- `throw_on_decode_error` (true): throw on invalid TOON; otherwise return `null`
- `numbers_as_strings` (false): decode numbers as strings instead of numeric types
- `spec_strict` (true): prefer strict spec behavior (no trailing newline, stricter normalization)

Features
--------

[](#features)

- Spec‑Conformant Headers
    - Primitive arrays: `[n]: v1,v2,v3`
    - Tabular arrays: `[n]{k1,k2}:` then rows indented one level
    - Delimiter suffix for non‑default delimiters in headers: `[n|]`, `[n\t]`
    - Empty arrays: `[0]:`
- Smart Tabular Encoding
    - Detects uniform lists of objects; emits compact tabular blocks with header fields
    - Human‑readable and token‑efficient (ideal for LLM prompts)
- Mixed Arrays with Nested Items
    - Renders `[n]:` then list items with `- `, and handles nested multi‑line blocks with correct indentation
- Safe Key Folding (optional)
    - `key_folding='safe'` flattens chains of single‑key nested objects into dot paths when safe; `flatten_depth` and `folding_exclude` supported
- Safe Path Expansion (optional)
    - `expand_paths=true` expands dotted keys into nested objects on decode (safe segments only)
- Robust Decoding and Validation
    - Strict indentation checks; array length and tabular row count validation
    - Configurable error handling via `throw_on_decode_error`
- Predictable String/Numeric Handling
    - Spec‑style quoting/escaping; optional `numbers_as_strings` mode
- First‑Class Laravel Integration
    - Facade `Toon::encode` / `Toon::decode`
    - Global helpers `toon_encode` / `toon_decode`
    - Container singleton and alias `'Toon'` for DI

Usage
-----

[](#usage)

### Facade

[](#facade)

```
use JobMetric\Toon\Facades\Toon;

$data = [
    'id' => 42,
    'tags' => ['x', 'y'],
    'users' => [
        ['id' => 1, 'name' => 'Alice'],
        ['id' => 2, 'name' => 'Bob'],
    ],
];

$toon = Toon::encode($data);
// [2]{id,name}:
//   1,Alice
//   2,Bob

$decoded = Toon::decode($toon);
// same as $data
```

### Helpers

[](#helpers)

```
$encoded = toon_encode(['numbers' => [1, 2, 3]]);
// [3]: 1,2,3

$decoded = toon_decode($encoded);
```

### Container/DI

[](#containerdi)

```
use JobMetric\Toon\ToonManager;

$toon = app(ToonManager::class)->encode(['items' => ['a', 'b']]);
// items[2]: a,b
```

### Custom Delimiter

[](#custom-delimiter)

```
config()->set('laravel-toon.delimiter', '|');

echo Toon::encode(['nums' => [1,2,3]]);
// nums[3|]: 1|2|3
```

### Safe Key Folding + Path Expansion

[](#safe-key-folding--path-expansion)

```
config()->set('laravel-toon.key_folding', 'safe');
config()->set('laravel-toon.expand_paths', true);

$encoded = Toon::encode(['a' => ['b' => ['c' => 1]]]);
// a.b.c: 1
$decoded = Toon::decode($encoded);
// ['a' => ['b' => ['c' => 1]]]
```

### Error Handling

[](#error-handling)

```
config()->set('laravel-toon.throw_on_decode_error', false);
$decoded = toon_decode("id:\n   name: Alice\n"); // null (no exception)
```

### Numbers as Strings

[](#numbers-as-strings)

```
config()->set('laravel-toon.numbers_as_strings', true);

$decoded = Toon::decode('n: 12345678901234567890');
// ['n' => '12345678901234567890']
```

Spec Notes (Parity)
-------------------

[](#spec-notes-parity)

- Headers only include delimiter suffix when non‑default (`,` is implicit): `[3|]`, `[2\t]`.
- Tabular header fields are delimited using the same active delimiter.
- Strings are quoted only when necessary (whitespace, delimiter present, structural chars, looks like literal/number, control chars, backslash).
- Keys are unquoted when safe; dotted keys allowed when each segment is a safe identifier.
- Decoder enforces indentation width to be multiples of `indent` (default `2`).

Why jobmetric/laravel-toon
--------------------------

[](#why-jobmetriclaravel-toon)

- Spec‑accurate TOON for Laravel (delimiter‑aware headers, robust parsing)
- Token‑efficient formatting — especially tabular encoding
- Safety controls (folding/expand for safe identifiers, strict indentation)
- Predictable numeric/string handling (optional strings for large numbers)
- Developer experience: Facade, helpers, alias, simple config

Contributing
------------

[](#contributing)

Thank you for considering contributing to Laravel Toon! Please see [CONTRIBUTING.md](https://github.com/jobmetric/laravel-toon/blob/master/CONTRIBUTING.md).

License
-------

[](#license)

The MIT License (MIT). See [LICENCE.md](https://github.com/jobmetric/laravel-toon/blob/master/LICENCE.md) for details.

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance73

Regular maintenance activity

Popularity24

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 75.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

177d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b00d08bd4b0b765ee2d33719a535e6cb49c04fb945078a0809d5c05e6f16ee96?d=identicon)[majidmohammadian](/maintainers/majidmohammadian)

---

Top Contributors

[![MajidMohammadian](https://avatars.githubusercontent.com/u/2099965?v=4)](https://github.com/MajidMohammadian "MajidMohammadian (22 commits)")[![Bagheri-Matin](https://avatars.githubusercontent.com/u/239607447?v=4)](https://github.com/Bagheri-Matin "Bagheri-Matin (7 commits)")

---

Tags

aichatgptcloudconvertercopilotdatadata-visualizationdeepseekgeminigrokjsonlaravellaravel-packagelaravel-toonlaraveltoonllmperplexityphptoken-optimizationtoonphpjsonlaravelaiopenaistructured-datallmChatGptpromptprompt-engineeringtoonjobmetricdata-serializationdata-conversiontoken-optimized

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/jobmetric-laravel-toon/health.svg)

```
[![Health](https://phpackages.com/badges/jobmetric-laravel-toon/health.svg)](https://phpackages.com/packages/jobmetric-laravel-toon)
```

###  Alternatives

[sbsaga/toon

🧠 TOON for Laravel — a compact, human-readable, and token-efficient data format for AI prompts &amp; LLM contexts. Perfect for ChatGPT, Gemini, Claude, Mistral, and OpenAI integrations (JSON ⇄ TOON).

6115.6k](/packages/sbsaga-toon)[helgesverre/toon

Token-Oriented Object Notation - A compact data format for reducing token consumption when sending structured data to LLMs

11841.4k9](/packages/helgesverre-toon)[rajentrivedi/tokenizer-x

TokenizerX calculates required tokens for given prompt

91214.0k3](/packages/rajentrivedi-tokenizer-x)[mischasigtermans/laravel-toon

Token-Optimized Object Notation encoder/decoder for Laravel with intelligent nested object handling

13113.1k](/packages/mischasigtermans-laravel-toon)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
