承接 basemax/toon-php 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

basemax/toon-php

Composer 安装命令:

composer require basemax/toon-php

包简介

PHP implementation of the TOON format (similar to JSON but shorter and better)

README 文档

README

TOON (Token-Oriented Object Notation) is a compact, human-readable serialization format designed specifically for representing JSON-like data in Large Language Model (LLM) prompts. It preserves the full structure of objects, arrays, and primitives from JSON while optimizing for token efficiency and parseability by AI models. By blending YAML's indentation-based nesting for hierarchical data with CSV-inspired tabular layouts for uniform arrays, TOON strikes a balance between brevity and clarity making it ideal for feeding structured data to LLMs without the verbosity of full JSON.

This PHP library is a complete, object-oriented port of the original TypeScript implementation (toon-format/toon). It supports lossless encoding from PHP data structures (arrays, objects, primitives) to TOON strings and decoding back, with advanced features like safe key folding, path expansion, custom delimiters, and strict validation modes.

Key Features

  • Token-Optimized Syntax: Minimizes LLM input tokens while remaining easy for models (and humans) to read and parse.
  • Hybrid Structure:
    • Indentation for nested objects (YAML-like).
    • Tabular rows for uniform arrays of objects (CSV-like, with explicit headers for reliability).
  • Lossless Round-Tripping: Encode PHP data to TOON and decode back without data loss, pairing well with JSON for programmatic use.
  • Advanced Options:
    • Key folding to collapse single-key chains into dotted paths (e.g., data.metadata.items).
    • Path expansion during decoding to reconstruct nested structures from dotted keys.
    • Custom indentation, delimiters (comma, tab, pipe), and flattening depth.
    • Strict mode for validation (e.g., array lengths, no extra rows/items).
  • Edge Case Handling: Supports quoted keys/values, escapes, booleans/null/numerics, empty structures, and mixed arrays.
  • PHP-Specific: Built for PHP 8+, with PSR-4 autoloading via Composer. No external dependencies.

TOON shines for uniform datasets (e.g., lists of records with consistent fields), achieving CSV compactness while adding LLM-friendly structure. For deeply irregular or nested data, traditional JSON may be more token-efficient. Think of TOON as a "prompt-friendly JSON translator": use JSON in code, TOON in AI interactions.

Installation

Install via Composer:

composer require basemax/toon-php

Quick Usage

<?php
require 'vendor/autoload.php';

use Toon\Toon;
use Toon\EncodeOptions;

$data = ['users' => [['id' => 1, 'name' => 'Alice'], ['id' => 2, 'name' => 'Bob']]];
$options = new EncodeOptions(indent: 4, delimiter: '|', keyFolding: 'safe');
$toon = Toon::decode($toon);

Why TOON?

  • LLM Efficiency: Reduces prompt size, helping models focus on logic over parsing.
  • Familiarity: Borrows from CSV/YAML for quick adoption.
  • Flexibility: Handles complex JSON equivalents reliably.
  • Open Source: MIT-licensed, community-driven evolution of the TOON spec.

Contributions welcome! See the original spec for details, or open issues for PHP-specific features.

Test

php test.php

Example

$data = ['name' => 'Alice', 'age' => 30];
echo Toon::encode($data) . PHP_EOL;

$toonString = "name: Alice\nage: 30";
var_dump(Toon::decode($toonString));

Copyright 2025, Seyyed Ali Mohammadiyeh (Max Base)

basemax/toon-php 适用场景与选型建议

basemax/toon-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8 次下载、GitHub Stars 达 4, 最近一次更新时间为 2025 年 11 月 15 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 basemax/toon-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 basemax/toon-php 我们能提供哪些服务?
定制开发 / 二次开发

基于 basemax/toon-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 8
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 20
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-11-15