Overview
The TOON JSON Converter provides separate option sets for encoding (JSON → TOON) and decoding (TOON → JSON) operations.Important: Encoding options only apply when converting TO TOON format. Decoding options only apply when converting TO JSON format.
General Options
Output Path
Specify the output file or folder path.Default: Auto-generated based on input filenameApplies to: All conversion modesSource: toon_json_converter.py:1204-1210
Usage
Auto-Generated Paths
When output is omitted, the converter generates the path automatically:| Input Pattern | Generated Output | Example |
|---|---|---|
*.json | *.toon | data.json → data.toon |
*.jsonl | *_toons/ | logs.jsonl → logs_toons/ |
*.toon | *.json | config.toon → config.json |
folder/ | folder.jsonl | data_toons/ → data_toons.jsonl |
toon_json_converter.py:1061-1076
Encoding Options (JSON → TOON)
These options control how JSON data is encoded into TOON format.Delimiter Options
Use tab (
\t) as the delimiter for tabular array values.Default: Comma (,)Applies to: Tabular arrays (arrays of objects with uniform keys)Source: toon_json_converter.py:1215-1216Data structure: Sets EncodeOptions.delimiter = Delimiter.TABExample: Default Comma Delimiter
Input JSON:Example: Tab Delimiter
Command:Header marker: When using
--tab, the header displays a space marker ( ) to indicate tab-separated values.Use pipe (
|) as the delimiter for tabular array values.Default: Comma (,)Applies to: Tabular arrays (arrays of objects with uniform keys)Source: toon_json_converter.py:1217-1218Data structure: Sets EncodeOptions.delimiter = Delimiter.PIPEExample: Pipe Delimiter
Command:Header marker: When using
--pipe, the header displays a pipe marker (|) inside the brackets.Delimiter Comparison
| Option | Delimiter Character | Header Marker | Use Case |
|---|---|---|---|
| Default | Comma (,) | None | Standard CSV-like data |
--tab | Tab (\t) | Space ( ) | Tab-separated values (TSV) |
--pipe | Pipe (|) | Pipe (|) | Pipe-delimited data |
Array Length Marker
Add
# prefix to array length indicators in headers.Default: No prefixApplies to: All array types (primitive, tabular, list)Source: toon_json_converter.py:1219-1220Data structure: Sets EncodeOptions.length_marker = TrueExample: Without Length Marker (Default)
Input JSON:Example: With Length Marker
Command:Benefits
- Improved readability: The
#makes array lengths visually distinct from index notation - Parsing clarity: Helps distinguish array headers from potential index-based keys
- Spec compliance: Follows TOON optional syntax for array length notation
Key Folding
Enable key folding for nested single-key objects. Converts chains of objects with single keys into dotted path notation.Default: DisabledApplies to: Nested objects where each level has exactly one keyRequirements: Keys must match pattern
[A-Za-z_][A-Za-z0-9_]* (alphanumeric + underscore, starting with letter/underscore)Source: toon_json_converter.py:1221-1222Data structure: Sets EncodeOptions.key_folding = TrueImplementation: KeyFolder class (toon_json_converter.py:278-306)Example: Without Key Folding (Default)
Input JSON:Example: With Key Folding
Command:Key Folding Rules
Key folding applies when ALL of these conditions are met:- ✅ Object has exactly one key
- ✅ Key matches pattern
[A-Za-z_][A-Za-z0-9_]* - ✅ Value is another object (continues the chain)
- ❌ Object has multiple keys
- ❌ Key contains special characters (
.,-, etc.) - ❌ Value is not an object (primitive, array, etc.)
- ❌ Max depth reached (default: infinite)
Example: Partial Key Folding
Input JSON:Folding stops at
connection because the next level has two keys (host and port).Example: Invalid Keys for Folding
Input JSON:Key folding doesn’t apply because
app-config contains a hyphen and api.endpoint contains a dot.Source Code Reference
Combining Encoding Options
You can combine multiple encoding options:Decoding Options (TOON → JSON)
These options control how TOON data is decoded into JSON format.Compact Output
Output minified JSON without whitespace or indentation.Default: Pretty-printed with 2-space indentationApplies to: TOON → JSON and Folder → JSONL conversionsSource: toon_json_converter.py:1228-1229Data structure: Sets
DecodeOptions.pretty = FalseExample: Pretty Output (Default)
Input:data.toon
data.json
Example: Compact Output
Command:data.json (single line)
Use Cases
| Mode | Use Case |
|---|---|
| Pretty (default) | Human-readable output, debugging, configuration files |
| Compact | Minimal file size, API responses, log files, machine processing |
Indentation
Set the number of spaces for JSON indentation.Default:
2Range: Any positive integerIgnored when: Used with --compact flagSource: toon_json_converter.py:1232-1238Data structure: Sets DecodeOptions.indentExample: Default 2-Space Indentation
Command:Example: 4-Space Indentation
Command:Example: Tab Indentation
To achieve tab indentation, you would need to post-process the output:Path Expansion
Expand dotted keys into nested objects during TOON → JSON conversion.Default: Disabled (per TOON spec §13.4)Applies to: Keys containing dots (
.) without bracketsSource: toon_json_converter.py:1230-1231Data structure: Sets DecodeOptions.expand_paths = TrueParser reference: toon_json_converter.py:656-657, 713-716Example: Without Path Expansion (Default)
Input:config.toon
config.json
By default, dotted keys are treated as literal string keys, not nested paths.
Example: With Path Expansion
Command:config.json
Path Expansion Rules
Expansion applies when:- ✅ Key contains dots (
.) - ✅ Key does NOT contain brackets (
[,]) - ✅
--expand-pathsflag is set
- ❌ Keys without dots
- ❌ Array notation like
items[0] - ❌ When
--expand-pathsis not set (default)
Example: Mixed Keys
Input:mixed.toon
items[2] is NOT expanded because it contains brackets (array notation).Source Code Reference
Complementary with Key Folding
--key-folding (encoding) and --expand-paths (decoding) are complementary:
Round-trip example:
Combining Decoding Options
You can combine decoding options:Combining
--compact with --indent will ignore the --indent value since compact mode removes all whitespace.Option Scope Summary
| Option | Applies When | Ignored When |
|---|---|---|
--tab | Converting JSON/JSONL → TOON | Converting TOON → JSON |
--pipe | Converting JSON/JSONL → TOON | Converting TOON → JSON |
--length-marker | Converting JSON/JSONL → TOON | Converting TOON → JSON |
--key-folding | Converting JSON/JSONL → TOON | Converting TOON → JSON |
--compact | Converting TOON → JSON/JSONL | Converting JSON → TOON |
--indent | Converting TOON → JSON/JSONL (without --compact) | Converting JSON → TOON, or with --compact |
--expand-paths | Converting TOON → JSON/JSONL | Converting JSON → TOON |
Next Steps
Batch Conversion
Learn batch processing workflows
Conversion Modes
Understand all four conversion modes
CLI Reference
Complete CLI command reference
TOON Format
Deep dive into TOON format specification