Indentation
TOON uses 2-space indentation by default to represent nesting levels:Indentation must be consistent throughout the document. Mixing tabs and spaces is not allowed.
Key-Value Pairs
Keys and values are separated by a colon (:) followed by optional whitespace:
Key Syntax
Keys follow identifier rules and may contain:- Letters (Unicode):
a-z,A-Z,α-ω, etc. - Digits:
0-9 - Underscores and dots:
_,.
When Keys Need Quotes
Keys must be quoted if they:- Are empty
- Don’t start with a letter or underscore
- Contain special characters (spaces,
:,[,],{,}, delimiters)
Keys matching the pattern
^[\w][\w.]*$ don’t need quotes (see toon_json_converter.py:65).Values
Primitives
TOON supports all JSON primitive types:Null
Booleans
Numbers
Numbers are written in canonical decimal form (no scientific notation by default):Leading zeros (e.g.,
007) are treated as strings and must be quoted if intended as strings.Strings
Strings may be unquoted if they follow safe identifier rules:String Quoting Rules
TOON uses smart quoting to minimize unnecessary quotes. Strings need quotes if they:1. Are Empty or Have Leading/Trailing Whitespace
2. Match Reserved Literals
3. Look Like Numbers
4. Start with a Hyphen
5. Contain Special Characters
Quotes are required for strings containing:- The active delimiter (
,,\t, or|) - Structural characters:
:,[,],{,},",\ - Newlines, carriage returns, or tabs
6. Look Like Array or Field Headers
Escape Sequences
Inside quoted strings, these escape sequences are supported:| Escape | Result |
|---|---|
\\ | Backslash (\) |
\" | Double quote (") |
\n | Newline |
\r | Carriage return |
\t | Tab |
Unlike JSON, TOON doesn’t support
\u Unicode escapes. Use UTF-8 encoding directly.Nested Objects
Objects are represented by indented key-value pairs:Empty Objects
Key Folding (Optional)
When enabled with--key-folding, nested single-key objects can be flattened using dot notation:
Key folding only works for keys matching
^[A-Za-z_][A-Za-z0-9_]*$ (see toon_json_converter.py:281).Path Expansion (Optional)
When decoding with--expand-paths, dotted keys are expanded into nested objects:
Delimiters
TOON supports three delimiters for array values:Comma (Default)
Tab
Use--tab flag for tab-separated values:
Pipe
Use--pipe flag for pipe-separated values:
Comments
Complete Example
Here’s a complete example demonstrating various syntax rules:For array syntax rules, see the Array Formats page.
Next Steps
Array Formats
Learn about TOON’s three array formats
Examples
See comprehensive real-world examples