Skip to content

P1: Add TOON encoder for JSON-array outputs (gh, kubectl, aws) #3

Closed

Description

@jhonatanjunio

Context

Token-Oriented Object Notation (TOON, https://github.com/toon-format/toon) is a schema-aware JSON replacement designed for LLM prompts. It cuts ~40% of tokens on arrays of uniform objects by emitting the schema once in a header (users[3]{id,name,role}:) and then rows.

Many gh/kubectl/aws/gcloud/az outputs are exactly this shape (--json, -o json, --output json, --format json). Squeez currently runs them through CloudHandler which only strips noise — never reformats. Free 40% on a large class of common dev commands.

Goal

Add an opt-in TOON re-encoding step to the CloudHandler (and any other JSON-emitting handlers later). When the captured output is a JSON array of flat, uniformly-shaped objects, emit TOON in place; otherwise pass through unchanged.

Acceptance criteria

  • New module src/strategies/toon.rs with:
    • try_to_toon(text: &str) -> Option<String> — zero-dep parser + emitter.
    • Returns Some(toon) only when input is a top-level JSON array of flat objects with identical key sets in identical order, and all values are primitives (string / number / bool / null).
    • Returns None for any deviation — never produces lossy output.
  • CloudHandler calls it before its existing pipeline; if Some, returns the TOON lines.
  • Unit tests cover: gh PR list shape, kubectl pods, aws ec2 describe, heterogeneous keys (must reject), nested values (must reject), single object (must reject), empty array.
  • Zero new runtime deps.

Out of scope

  • Streaming JSON (NDJSON from docker ps --format '{{json .}}') — handled in a follow-up.
  • cargo metadata — nested structures, not worth TOON.

Activity

  1. jhonatanjunio commented on May 18, 2026

    @jhonatanjunio
    OwnerAuthor

    Moved to upstream claudioemmanuel/squeez. Superseded.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions