Quick Start Guide

Get started with the TON file format in just a few minutes. This guide covers the basics you need to know.

Your First TON File

Create a file called example.ton with the following content:

# This is a comment
{(config)
    # Basic properties
    appName = "MyApplication",
    version = "1.0.0",
    debug = true,
    port = 8080,

    # Multi-line string
    description = """
    This is my application.
    It does amazing things!
    """,

    # Array
    features = ["auth", "api", "websocket"],

    # Nested object
    database = {
        host = "localhost",
        port = 5432,
        name = "mydb"
    }
}

Basic Syntax Rules

1. Objects

All TON files start with an object, optionally typed with a class name in parentheses:

{(className)
    property = value
}

2. Properties

Properties use the name = value syntax. Property names can be unquoted if they're simple identifiers:

{
    simpleName = "value",
    "complex.name" = "needs quotes",
    123 = "numeric property names allowed",
    @prefixed = "optional @ prefix"
}

3. Data Types

Type Example Notes
String "text" or 'text' Always quoted
Number 42, 3.14, 0xFF Unquoted, supports hex/binary
Boolean true, false Unquoted
Null null Unquoted
Array [1, 2, 3] Square brackets
Date "2024-01-15T10:30:00Z" ISO 8601, quoted
GUID 550e8400-e29b-41d4-a716-446655440000 Unquoted
Enum |active| Pipe delimited

Multi-line Strings

TON supports multi-line strings with automatic indentation handling:

{
    sql = """
    SELECT u.id, u.name, u.email
    FROM users u
    WHERE u.active = true
    ORDER BY u.created_at DESC
    """,

    javascript = '''
    function greet(name) {
        return `Hello, ${name}!`;
    }
    '''
}

Comments

TON supports both single-line and multi-line comments:

{
    // Single-line comment
    property1 = "value",

    /* Multi-line comment
       can span multiple lines */
    property2 = "value",

    # Alternative single-line comment
    property3 = "value"
}

Schema Validation

Add schema definitions at the end of your file to validate data:

{(user)
    id = 123,
    name = "John Doe",
    email = "[email protected]"
}

#! {(user)
    /id = int(required, positive),
    /name = string(required, maxLength(100)),
    /email = string(required, format(email))
}

Type Hints

Optional type hints can make data types more explicit:

{
    name = $"John Doe",        // $ = string hint
    count = %42,               // % = number hint
    id = &550e8400-e29b-41d4-a716-446655440000,  // & = GUID hint
    items = ^["a", "b", "c"]   // ^ = array hint
}

Next Steps

Try It Now

Install the TON parser for your language:

C#/.NET

dotnet add package DevPossible.Ton
using DevPossible.Ton;

var parser = new TonParser();
var document = parser.Parse(File.ReadAllText("example.ton"));

// Access data
var appName = document.RootObject["appName"].ToString();
var port = document.RootObject["port"].ToInt32();

JavaScript (Coming Soon)

npm install @devpossible/ton
import { parse } from '@devpossible/ton';

const document = parse(fs.readFileSync('example.ton', 'utf8'));
console.log(document.appName);