TONL Format
Understanding the TONL format specification.
Structure
A TONL document consists of three parts:
collection_name[count]{schema}: data- Header: Collection name and count
- Schema: Type definitions for columns
- Data: Comma-separated values
Header
Format: name[count]
users[3]users: Collection name3: Number of objects
Schema
Format: {column:type,column:type,...}
{id:i8,name:str,age:i8}Types are optimized based on data:
i8: 8-bit integer (-128 to 127)i16: 16-bit integer (-32,768 to 32,767)i32: 32-bit integerstr: Stringbool: Booleanf32: 32-bit floatf64: 64-bit float
Data Rows
Each row on a new line, comma-separated:
1, Alice, 25
2, Bob, 30
3, Charlie, 35Complete Example
users[3]{id:i8,name:str,age:i8}:
1, Alice, 25
2, Bob, 30
3, Charlie, 35Equivalent JSON:
json
[
{"id": 1, "name": "Alice", "age": 25},
{"id": 2, "name": "Bob", "age": 30},
{"id": 3, "name": "Charlie", "age": 35}
]Nested Objects
Nested objects are preserved:
users[1]{id:i8,profile:obj}:
1, {name:Alice,email:alice@example.com}Or flatten with option:
typescript
jsonToTonl(data, 'users', { flattenNested: true });Result:
users[1]{id:i8,profile_name:str,profile_email:str}:
1, Alice, alice@example.comArrays
Arrays are preserved as values:
users[1]{id:i8,tags:arr}:
1, [developer,typescript]Special Values
null: Represents null values- Empty strings: Preserved as-is
- Booleans:
trueorfalse
Parsing Rules
When parsing TONL back to JSON:
- Schema defines output structure
- Types are converted automatically
- Nested structures are restored
- Arrays are reconstructed
Validation
TONL validates:
- Schema consistency across all objects
- Type compatibility
- Data integrity
- Row count matches header
Limitations
- All objects must have consistent schema
- Column order must remain stable
- No circular references in nested objects
- Maximum row count: determined by memory