Converting JSON toTOON format is straightforward when you understand the mapping between JSON structures and TOON's token-efficient notation. This guide walks through the conversion process with real-world examples.
By the end of this guide, you'll be able to manually convert JSON to TOON or use ourJSON to TOON converter with confidence, understanding exactly how the conversion works and when to optimize further.
Understanding the Conversion Principles
Before diving into conversions, understand these core principles:
1. Simple Key-Value Pairs
JSON's "key": "value" becomes TOON'skey: "value" (no quotes on keys)
2. Arrays Become Structured
JSON arrays of objects get converted to TOON's structured array notation with field definitions, eliminating repeated property names - this is where the 50% token savings comes from.
3. Indentation Replaces Braces
JSON's curly braces {} for objects become indentation-based hierarchy in TOON, similar to YAML but more token-efficient.
Step 1: Converting Simple Objects
Start with the simplest conversion - a basic JSON object with primitive values:
Original JSON
{
"name": "Sarah Mitchell",
"age": 32,
"email": "[email protected]",
"active": true,
"role": "Senior Developer"
}Converted TOON
name: "Sarah Mitchell" age: 32 email: "[email protected]" active: true role: "Senior Developer"
Conversion Rules Applied:
- •Remove outer curly braces - TOON doesn't require them for root object
- •Remove quotes from property names (keys)
- •Keep quotes on string values
- •Use colon for key-value separation (no comma at line end)
Step 2: Converting Nested Objects
Nested objects use indentation to represent hierarchy:
Original JSON
{
"user": {
"name": "Alex Johnson",
"email": "[email protected]"
},
"address": {
"street": "123 Main St",
"city": "Boston",
"zipCode": "02101"
}
}Converted TOON
user: name: "Alex Johnson" email: "[email protected]" address: street: "123 Main St" city: "Boston" zipCode: "02101"
Key Points:
- •Parent key followed by colon, then newline
- •Indent child properties by 2 spaces
- •Each nesting level adds 2 more spaces of indentation
Step 3: Converting Arrays of Primitives
Simple arrays containing strings, numbers, or booleans:
Original JSON
{
"tags": ["javascript", "react", "typescript"],
"scores": [95, 87, 92, 88],
"features": ["fast", "secure", "scalable"]
}Converted TOON
tags[3]: "javascript", "react", "typescript" scores[4]: 95, 87, 92, 88 features[3]: "fast", "secure", "scalable"
Array Conversion Rules:
- 1.Add length marker in brackets:
arrayName[count] - 2.Follow with colon and space
- 3.List values separated by commas (single line for primitive arrays)
- 4.Count elements accurately - length marker must match actual count
Step 4: Converting Arrays of Objects (Token Savings!)
This is where TOON achieves its 50% token reduction - arrays of objects become structured arrays:
Original JSON (95 tokens)
{
"customers": [
{
"id": 1,
"name": "Sarah Mitchell",
"email": "[email protected]",
"active": true
},
{
"id": 2,
"name": "Michael Chen",
"email": "[email protected]",
"active": true
},
{
"id": 3,
"name": "Jennifer Kumar",
"email": "[email protected]",
"active": false
}
]
}Converted TOON (48 tokens - 50% reduction!)
customers[3]{id,name,email,active}:
1,Sarah Mitchell,[email protected],true
2,Michael Chen,[email protected],true
3,Jennifer Kumar,[email protected],falseStructured Array Conversion Process:
- 1.Identify common properties: All objects in the array have the same properties (id, name, email, active)
- 2.Create field definition: List property names once in curly braces:
{id,name,email,active} - 3.Add length marker: Count objects and add bracket notation:
[3] - 4.Create data rows: Each object becomes a comma-separated row with values in field order
- 5.Indent rows: Indent each data row by 2 spaces for readability
Step 5: Converting Complex Nested Structures
Real-world data often combines objects, nested objects, and arrays:
Original JSON
{
"company": "Tech Solutions Inc",
"employees": [
{
"id": 101,
"name": "Sarah Mitchell",
"role": "Engineer",
"salary": 95000
},
{
"id": 102,
"name": "Michael Chen",
"role": "Designer",
"salary": 85000
}
],
"metadata": {
"created": "2025-01-15",
"version": 2
}
}Converted TOON
company: "Tech Solutions Inc"
employees[2]{id,name,role,salary}:
101,Sarah Mitchell,Engineer,95000
102,Michael Chen,Designer,85000
metadata:
created: "2025-01-15"
version: 2Strategy for Complex Conversions:
- •Process top-level properties first
- •Convert arrays of objects to structured arrays (maximum efficiency)
- •Use indentation for nested objects
- •Maintain consistent indentation (2 spaces per level)
Handling Special Cases
Case 1: Data Contains Commas
When values contain commas, use pipe delimiter instead:
# JSON with comma-containing values
# addresses: [{"street": "123 Main St, Suite 100", "city": "Boston"}]
# TOON with pipe delimiter
addresses[1]{street,city}|:
123 Main St Suite 100|BostonCase 2: Null Values
JSON null becomes TOON null:
# JSON: {"name": "John", "middleName": null, "age": 30}
# TOON:
name: "John"
middleName: null
age: 30Case 3: Empty Arrays
Empty arrays are explicitly marked:
# JSON: {"tags": [], "count": 0}
# TOON:
tags[0]:
count: 0Case 4: Mixed Array Types
If array objects have different properties, use nested object notation:
# When objects have inconsistent properties
items[2]:
- id: 1
type: "product"
price: 99.99
- id: 2
type: "service"
duration: "1 hour"Optimization Tips
Prioritize Arrays of Objects
These benefit most from TOON conversion. Focus your conversion efforts on arrays of objects with consistent properties - they'll show the biggest token reduction.
Use Our Converter Tool
For large JSON files, use our JSON to TOON converter which automatically handles all conversion rules and optimization.
Validate After Conversion
Always run converted TOON through our TOON Validator to catch syntax errors, length mismatches, or formatting issues.
Add Comments for Context
TOON supports comments. Add them to explain data structure or provide context for LLMs:
# Customer churn analysis data - Q4 2024
customers[3]{id,name,churn_risk}:
1,Sarah Mitchell,0.15
2,Michael Chen,0.82Post-Conversion Verification Checklist
- ☐All array length markers match actual element counts
- ☐Structured array rows have same number of values as fields defined
- ☐Indentation is consistent (2 spaces per level)
- ☐String values are properly quoted
- ☐Boolean values are lowercase (true/false)
- ☐No trailing commas on lines
- ☐Validated with TOON Validator
- ☐Test conversion is reversible with TOON to JSON
Practice Example: Try It Yourself
Test your understanding by converting this JSON to TOON:
{
"project": "E-commerce Platform",
"team_members": [
{"id": 1, "name": "Alice", "role": "Lead", "hours": 40},
{"id": 2, "name": "Bob", "role": "Developer", "hours": 35},
{"id": 3, "name": "Carol", "role": "Designer", "hours": 30}
],
"budget": {
"allocated": 50000,
"spent": 32000,
"remaining": 18000
},
"status": "In Progress"
}Click to see the answer
project: "E-commerce Platform"
team_members[3]{id,name,role,hours}:
1,Alice,Lead,40
2,Bob,Developer,35
3,Carol,Designer,30
budget:
allocated: 50000
spent: 32000
remaining: 18000
status: "In Progress"Conversion Tools
External Resources
- •What is TOON Format? - Introduction and basics
- •TOON Format Specification - Complete syntax reference
- •TOON vs JSON Comparison - Token savings analysis
- •TOON Official GitHub - Libraries and code examples
- •OpenAI Tokenizer - Compare JSON vs TOON token counts
- •JSON Official Website - Understanding JSON format basics