TOON by Example

Practical examples demonstrating the syntax and structure of TOON.

Basic Structures

Simple Key-Value

The most basic structure, mapping keys to primitive values like strings, numbers, and booleans.

name: Cake
ppu: 0.55
is_good: true

Nested Objects

Use indentation to create nested objects for logical grouping of related data.

batters:
  batter:
    id: 1001
    type: Regular

Arrays

TOON has a special, token-efficient syntax for handling arrays of primitive values and arrays of objects.

Primitive Arrays

A single-line, comma-separated list for simple values. The header specifies the item count.

tags[4]: "sci-fi", "dystopian", "classic", "must-read"

Tabular (Object) Arrays

For lists of objects with a consistent structure. Define columns in the header, followed by CSV-style rows.

users[3]{id,name,role}:
  1,Alice,admin
  2,Bob,editor
  3,Charlie,viewer

Putting It All Together

Complex API Response

A more complex example mimicking an API response, combining nested objects and tabular arrays.

product:
  id: 001
  type: donut
  name: Cake
  ppu: 0.55
  batters[2]{id,type}:
    1001,Regular
    1002,Chocolate
  toppings[2]{id,type}:
    5001,None
    5002,Glazed

Configuration File

TOON is great for config files. This example shows a typical setup for a web application.

config:
  app_name: My App
  version: 1.2.0
  database:
    host: db.example.com
    port: 5432
    user: admin
  features:
    enable_beta: true
    dark_mode: auto
  api_keys[2]: "key-123-abc", "key-456-def"