PHPackages                             fontebasso/json-to-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. [Utility &amp; Helpers](/categories/utility)
4. /
5. fontebasso/json-to-toon

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

fontebasso/json-to-toon
=======================

json-to-toon converts verbose JSON into a lightweight, LLM-friendly “Toon” format — optimized for ChatGPT and other AI models to cut token usage, boost context efficiency, and keep responses sharp.

1.0.0(6mo ago)04MITPHPCI passing

Since Nov 12Pushed 6mo agoCompare

[ Source](https://github.com/fontebasso/json-to-toon)[ Packagist](https://packagist.org/packages/fontebasso/json-to-toon)[ RSS](/packages/fontebasso-json-to-toon/feed)WikiDiscussions main Synced 1mo ago

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

json-to-toon
============

[](#json-to-toon)

[![Tests](https://github.com/fontebasso/json-to-toon/actions/workflows/tests.yml/badge.svg)](https://github.com/fontebasso/json-to-toon/actions/workflows/tests.yml)[![License: MIT](https://camo.githubusercontent.com/08cef40a9105b6526ca22088bc514fbfdbc9aac1ddbf8d4e6c750e3a88a44dca/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d626c75652e737667)](https://opensource.org/licenses/MIT)

`json-to-toon` is a lightweight PHP library that converts verbose JSON into a compact, LLM-optimized format called TOON. The TOON format preserves structure while minimizing token usage, improving context efficiency for large language models such as ChatGPT and Claude.

This implementation follows the [TOON Specification v2.0](https://github.com/toon-format/spec), supporting arrays, nested objects, primitives, and non-uniform structures — including compact representation of associative and nested data.

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

[](#installation)

You can install the library via Composer:

```
composer require fontebasso/json-to-toon
```

Overview
--------

[](#overview)

Traditional JSON structures are often verbose and redundant, especially when serialized for language models. `json-to-toon` introduces a concise syntax that encodes data in a tabular form, preserving semantics while reducing size.

### Example

[](#example)

Input JSON:

```
[
  {"id": 1, "name": "Alice", "role": "admin"},
  {"id": 2, "name": "Bob", "role": "user"}
]
```

Converted Toon:

```
users[2]{id,name,role}:
1,Alice,admin
2,Bob,user
```

This representation is shorter, token-efficient, and ideal for transmitting structured context to LLMs such as ChatGPT or Claude.

Usage
-----

[](#usage)

### From PHP Array

[](#from-php-array)

```
