Converting JSON toTOON format can reduce your LLM token usage by up to 50%. The conversion process follows a few straightforward rules.
This guide shows you how to convert JSON to TOON with step-by-step examples. You can convert files manually or use ourJSON to TOON converter tool.
What You'll Learn
- •Core conversion rules for standard use cases
- •Array conversion techniques for maximum token savings
- •Handling nested objects and special cases
- •Verification steps to ensure correct conversion
Core Conversion Rules
TOON conversion follows three basic rules:
No Quotes on Keys
JSON:
"name": "John"TOON:
name: "John"Remove quotes from property names.
List Fields Once
Instead of repeating:
{id: 1, name: "A"}
{id: 2, name: "B"}Define once:
{id,name}This provides the majority of token savings.
Use Indentation
JSON:
{user: {...}}TOON:
user:
...Use 2 spaces for each nesting level.
These three rules cover most conversion scenarios. The following examples demonstrate how to apply them.
Step 1: Simple Objects
Start with a basic JSON object to understand the fundamental transformation:
{
"name": "Sarah Mitchell",
"age": 32,
"email": "[email protected]",
"active": true,
"role": "Senior Developer"
}name: "Sarah Mitchell" age: 32 email: "[email protected]" active: true role: "Senior Developer"
Changes Applied
- 1.Removed outer curly braces - TOON doesn't need them for the root object
- 2.Removed quotes from keys -
"name"→name - 3.Kept quotes on string values - "Sarah Mitchell" stays quoted
- 4.Removed commas at the end of lines - TOON uses line breaks instead
Result: Cleaner syntax with reduced token count.
Step 2: Nested Objects
For nested objects, TOON uses indentation instead of curly braces, similar to Python or YAML:
{
"user": {
"name": "Maeve Winters",
"email": "[email protected]"
},
"address": {
"street": "123 Main St",
"city": "Boston",
"zipCode": "02101"
}
}user: name: "Maeve Winters" email: "[email protected]" address: street: "123 Main St" city: "Boston" zipCode: "02101"
Indentation Rules
- •Parent key + colon → then hit Enter
- •Indent children by 2 spaces (not tabs)
- •Each level deeper adds 2 more spaces
- •No closing braces needed - indentation defines structure
Step 3: Arrays of Simple Values
Arrays of strings, numbers, or booleans use a length marker notation:
{
"tags": ["javascript", "react", "typescript"],
"scores": [95, 87, 92, 88],
"features": ["fast", "secure", "scalable"]
}tags[3]: "javascript", "react", "typescript" scores[4]: 95, 87, 92, 88 features[3]: "fast", "secure", "scalable"
Array Syntax
arrayName[count]: value1, value2, value3- 1.Name + Length:
tags[3]means "tags array with 3 items" - 2.Colon + Space: Separate the declaration from values
- 3.List values: Comma-separated on a single line
- Note:Count must match - If you say [3], there must be exactly 3 items
Step 4: Arrays of Objects
Primary Token Savings
Converting arrays of objects provides the largest token reduction. This technique can reduce token usage by approximately 50%.
Instead of repeating property names for every object, TOON lets you define them once at the top:
{
"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
}
]
}customers[3]{id,name,email,active}:
1,Sarah Mitchell,[email protected],true
2,Michael Chen,[email protected],true
3,Jennifer Kumar,[email protected],falseSaved 47 tokens = 50% reduction
Applied across thousands of records, this adds up to significant cost savings.
Step-by-Step Conversion Process
- 1Identify common properties: All objects have the same keys:
id, name, email, active - 2Count the objects: There are 3 customers
- 3Write the header:
customers[3]{id,name,email,active}:- •
[3]= number of objects - •
{id,name,email,active}= field names (defined once)
- •
- 4Create data rows: Each object becomes one line with values in the same order as fields
1,Sarah Mitchell,[email protected],true - 5Indent each row: Add 2 spaces before each data row 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.82Common Mistakes to Avoid
- •Array count mismatch - if you write
[3], make sure there are exactly 3 items - •Inconsistent indentation - use 2 spaces, not tabs or 4 spaces
- •Missing quotes on strings - numbers don't need quotes, but text does
- •Wrong boolean format - use lowercase
trueandfalse - •Field order mismatch in arrays - values must match the order in
{field1,field2}
Use the TOON Validator to catch these errors automatically.
Quick Reference
Simple Object
name: "value"
age: 25Nested Object
user:
name: "value"
age: 25Simple Array
tags[3]: "a", "b", "c"Array of Objects
users[2]{id,name}:
1,Alice
2,BobConversion Tools
Use these tools for automated conversion and validation:
Additional Resources
Learn more about TOON and JSON with these resources:
TOON Documentation
- What is TOON Format?
Start here if you're new to TOON
- TOON vs JSON Comparison
See detailed token savings analysis
- TOON Format Specification
Complete syntax reference
- TOON Official GitHub
Libraries and code examples
Advanced Topics
- TOON for LLM Prompts
Best practices for AI applications
- OpenAI Tokenizer
Compare JSON vs TOON token counts
- JSON Official Website
Understanding JSON format basics