Skip to content

Conversation

@panbanda
Copy link

Summary

This PR introduces a new TOON type that automatically converts JSON payloads to compact TOON format when unmarshaling. The type implements standard Go interfaces for seamless integration with JSON, text formats, and databases.

Changes

New TOON Type (api.go)

  • Added type TOON []byte with complete interface implementations
  • json.Marshaler/Unmarshaler - Automatic JSON ↔ TOON conversion
  • encoding.TextMarshaler/Unmarshaler - Text format support
  • database/sql.Scanner/driver.Valuer - Database operations
  • fmt.Stringer - String representation via String() method
  • Helper method IsNil() for checking empty/nil values

Codec Integration

  • internal/codec/normalize.go: Added support for encoding.TextMarshaler interface
  • internal/codec/unmarshal.go: Added support for encoding.TextUnmarshaler interface

Documentation

  • README.md: Added comprehensive section "Capturing Tool Call Payloads with the TOON Type" (lines 107-188)
  • Documents automatic JSON-to-TOON conversion use case
  • Shows why TOON is beneficial: 30-50% smaller, human-readable, round-trip safe

Examples

  • examples/json_payload/main.go: Demonstrates JSON payload capture with automatic conversion
  • examples/toon_type/main.go: Shows basic TOON type operations
  • examples/tool_response/main.go: Illustrates tool call workflow storage

Tests

  • tests/toon_type_test.go: Comprehensive test coverage
    • 11 test functions, 34 sub-tests
    • Tests all interfaces: TextMarshaler, JSON, Scanner/Valuer, String, IsNil
    • Validates struct embedding, round-trip scenarios, nil handling
    • JSON-to-TOON automatic conversion tests

Test Plan

  • All new tests pass (11 functions, 34 sub-tests)
  • Existing tests remain passing (41/43 - 2 pre-existing spec failures)
  • JSON-to-TOON automatic conversion verified
  • Round-trip safety confirmed (JSON → TOON → JSON)
  • Database operations tested (Scan/Value)
  • Text marshaling tested (MarshalText/UnmarshalText)
  • Examples run successfully
  • Documentation reviewed

Introduce new TOON type that automatically converts JSON payloads to
compact TOON format when unmarshaling. The type implements standard Go
interfaces for seamless integration with JSON, text formats, and databases.

Key features:
- Automatic JSON-to-TOON conversion via json.Marshaler/Unmarshaler
- Text format support via encoding.TextMarshaler/Unmarshaler
- Database operations via sql.Scanner/driver.Valuer
- Round-trip safe: JSON → TOON → JSON conversion
- Helper methods: String(), IsNil()

Includes comprehensive tests (11 test functions, 34 sub-tests) and
examples demonstrating usage with tool call payloads and nested JSON objects.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant