Contents

alexey1312/TOONDecoder

A Swift decoder for Token-Oriented Object Notation

Features

TOONDecoder conforms to TOON specification version 3.0 (2025-11-24) and implements the following features:

  • [x] Correct escape sequence parsing (\\, \", \n, \r, \t)
  • [x] Three delimiter types: comma (default), tab, pipe
  • [x] Array length validation
  • [x] Tabular format parsing with field headers
  • [x] Inline format for primitive arrays
  • [x] Expanded list format for nested structures
  • [x] Path expansion to unfold dotted keys into nested objects (inverse of key folding)
  • [x] Detailed error reporting with line numbers

Requirements

  • Swift 6.0+ / Xcode 16+
  • iOS 13.0+ / macOS 10.15+ / watchOS 6.0+ / tvOS 13.0+ / visionOS 1.0+ / Linux

Installation

Swift Package Manager

Add the following to your Package.swift file:

dependencies: [
    .package(url: "https://github.com/alexey1312/TOONDecoder.git", from: "0.1.0")
]

Usage

Basic Decoding

import TOONDecoder

struct User: Codable {
    let id: Int
    let name: String
    let tags: [String]
    let active: Bool
}

let toon = """
id: 123
name: Ada
tags[2]: reading,gaming
active: true
"""

let decoder = TOONDecoder()
let user = try decoder.decode(User.self, from: Data(toon.utf8))
print(user.name) // "Ada"

Tabular Format

struct Item: Codable {
    let sku: String
    let qty: Int
    let price: Double
}

struct Order: Codable {
    let items: [Item]
}

let toon = """
items[2]{sku,qty,price}:
  A1,2,9.99
  B2,1,14.5
"""

let decoder = TOONDecoder()
let order = try decoder.decode(Order.self, from: Data(toon.utf8))
print(order.items.count) // 2

Path Expansion

Path expansion unfolds dotted keys into nested objects — the inverse of TOONEncoder's key folding:

struct Config: Codable {
    struct Database: Codable {
        struct Connection: Codable {
            let host: String
            let port: Int
        }
        let connection: Connection
    }
    let database: Database
}

let toon = """
database.connection.host: localhost
database.connection.port: 5432
"""

let decoder = TOONDecoder()
decoder.expandPaths = .safe
let config = try decoder.decode(Config.self, from: Data(toon.utf8))
print(config.database.connection.host) // "localhost"

Version Information

Check the supported TOON specification version:

print(TOONDecoder.specVersion) // "3.0"

License

This project is available under the MIT license. See the LICENSE file for more info.

Package Metadata

Repository: alexey1312/TOONDecoder

Stars: 1

Forks: 0

Open issues: 0

Default branch: main

Primary language: swift

License: MIT

README: README.md

Archived: yes