Ready to start saving on your LLM API costs? Converting JSON to TOON is easier than you think. Follow these 5 simple steps to transform your data and start seeing immediate token reductions.
What You'll Learn
By the end of this guide, you'll be able to:
- Convert any JSON structure to TOON format
- Understand the transformation rules
- Avoid common conversion mistakes
- Validate your converted data
- Use conversion tools effectively
Before You Start
Prerequisites:
- Basic understanding of JSON
- A JSON file to convert
- 10 minutes of your time
Tools Needed:
- Text editor (VS Code, Sublime, or any editor)
- Optional: Online TOON converter for validation
Let's dive in!
Step 1: Remove Curly Braces
The first and most visible change is eliminating curly braces.
JSON Structure
{
"name": "Alice",
"age": 30
}
Action: Remove Braces
"name": "Alice",
"age": 30
Rule: Delete the opening { and closing } from your object.
Why: TOON uses indentation to show structure, making braces unnecessary.
For Nested Objects
JSON:
{
"user": {
"name": "Bob"
}
}
Step 1 Result:
"user": {
"name": "Bob"
}
We'll handle the nested braces in later steps.
Step 2: Remove Quotes from Keys
Keys in TOON don't need quotation marks.
Starting Point
"name": "Alice",
"age": 30
Action: Remove Key Quotes
name: "Alice",
age: 30
Rule: Remove quotes around keys, but keep quotes around string values (for now).
Multiple Keys Example
Before:
"firstName": "John",
"lastName": "Doe",
"email": "john@example.com"
After:
firstName: "John",
lastName: "Doe",
email: "john@example.com"
Pro Tip: If a key contains special characters or spaces, you may need to keep quotes, but this is rare.
Step 3: Clean Up Value Formatting
Now let's handle values and remove unnecessary punctuation.
Remove Commas Between Lines
name: "Alice",
age: 30
Becomes:
name: "Alice"
age: 30
Rule: Each key-value pair goes on its own line. Commas are no longer needed.
Simplify String Values
For simple strings without spaces or special characters:
Before:
name: "Alice"
status: "active"
After:
name: Alice
status: active
When to Keep Quotes:
- Strings with spaces:
title: "Hello World" - Strings with special characters:
message: "Say \"Hi\"" - Numbers as strings:
id: "12345"(if ID should remain a string)
Handle Other Data Types
Numbers (stay the same):
age: 30
price: 29.99
Booleans (stay the same):
isActive: true
isVerified: false
Null (stays the same):
middleName: null
Step 4: Convert Nested Structures
Nested objects use indentation instead of braces.
Simple Nesting
JSON:
{
"user": {
"name": "Bob",
"age": 25
}
}
TOON:
user:
name: Bob
age: 25
Rule:
- Remove braces from nested objects
- Add 2 spaces of indentation for nested content
- Parent key ends with a colon
Deep Nesting (3 Levels)
JSON:
{
"company": {
"department": {
"name": "Engineering",
"size": 50
}
}
}
TOON:
company:
department:
name: Engineering
size: 50
Each nesting level = 2 more spaces of indentation
Mixed Nesting
JSON:
{
"user": {
"name": "Alice",
"contact": {
"email": "alice@example.com",
"phone": "555-0100"
}
},
"status": "active"
}
TOON:
user:
name: Alice
contact:
email: alice@example.com
phone: 555-0100
status: active
Note: The status key is at the root level (no indentation) because it's not nested under user.
Step 5: Handle Arrays Properly
Arrays require special attention in TOON.
Simple Arrays
JSON:
{
"colors": ["red", "green", "blue"]
}
TOON:
colors: [red, green, blue]
Rule: Simple arrays stay in bracket notation. Remove quotes if values are simple strings.
Arrays of Primitive Values
Numbers:
scores: [95, 87, 92, 88]
Mixed Types:
data: [42, true, null, "text"]
Arrays of Objects
This is where TOON really shines:
JSON:
{
"users": [
{
"id": 1,
"name": "Alice"
},
{
"id": 2,
"name": "Bob"
}
]
}
TOON:
users:
- id: 1
name: Alice
- id: 2
name: Bob
Rule:
- Each array item starts with a dash (
-) - Dash is at the indentation level of the array content
- Object properties are indented 2 spaces from the dash
Complex Array Example
JSON:
{
"teams": [
{
"name": "Engineering",
"members": [
{
"name": "Alice",
"role": "Lead"
},
{
"name": "Bob",
"role": "Developer"
}
]
}
]
}
TOON:
teams:
- name: Engineering
members:
- name: Alice
role: Lead
- name: Bob
role: Developer
Empty Arrays
JSON:
{
"items": []
}
TOON:
items: []
Rule: Empty arrays remain as []
Complete Conversion Example
Let's put it all together with a realistic example.
Original JSON
{
"id": 12345,
"user": {
"firstName": "John",
"lastName": "Doe",
"email": "john@example.com",
"age": 30,
"isVerified": true
},
"preferences": {
"theme": "dark",
"notifications": {
"email": true,
"push": false
}
},
"tags": ["developer", "javascript", "nodejs"],
"projects": [
{
"id": 1,
"name": "Website Redesign",
"status": "active"
},
{
"id": 2,
"name": "Mobile App",
"status": "completed"
}
]
}
Step-by-Step Transformation
After Step 1 (Remove braces at root):
"id": 12345,
"user": {
"firstName": "John",
...
},
...
After Step 2 (Remove key quotes):
id: 12345,
user: {
firstName: "John",
...
},
...
After Step 3 (Clean formatting):
id: 12345
user: {
firstName: John
lastName: Doe
email: john@example.com
age: 30
isVerified: true
}
preferences: {
theme: dark
notifications: {
email: true
push: false
}
}
tags: [developer, javascript, nodejs]
projects: [
{
id: 1
name: Website Redesign
status: active
},
{
id: 2
name: Mobile App
status: completed
}
]
After Step 4 (Convert nesting):
id: 12345
user:
firstName: John
lastName: Doe
email: john@example.com
age: 30
isVerified: true
preferences:
theme: dark
notifications:
email: true
push: false
tags: [developer, javascript, nodejs]
projects: [
{
id: 1
name: Website Redesign
status: active
},
{
id: 2
name: Mobile App
status: completed
}
]
After Step 5 (Fix arrays - Final TOON):
id: 12345
user:
firstName: John
lastName: Doe
email: john@example.com
age: 30
isVerified: true
preferences:
theme: dark
notifications:
email: true
push: false
tags: [developer, javascript, nodejs]
projects:
- id: 1
name: Website Redesign
status: active
- id: 2
name: Mobile App
status: completed
Token Count:
- JSON: ~245 tokens
- TOON: ~135 tokens
- Reduction: 45%
Common Mistakes and How to Fix Them
Mistake 1: Inconsistent Indentation
❌ Wrong:
user:
name: John
age: 30
✅ Correct:
user:
name: John
age: 30
Fix: Use exactly 2 spaces per indentation level consistently.
Mistake 2: Forgetting Colons
❌ Wrong:
user
name: John
✅ Correct:
user:
name: John
Fix: Parent keys always end with a colon.
Mistake 3: Wrong Array Syntax
❌ Wrong:
items:
1, 2, 3
✅ Correct:
items: [1, 2, 3]
Fix: Simple arrays use bracket notation.
Mistake 4: Incorrect Dash Placement
❌ Wrong:
users:
- id: 1
name: Alice
✅ Correct:
users:
- id: 1
name: Alice
Fix: Dash should be indented at the level of array content.
Mistake 5: Over-Quoting
❌ Wrong:
name: "John"
age: "30"
status: "active"
✅ Correct:
name: John
age: 30
status: active
Fix: Only quote strings that need it (with spaces/special characters).
Quick Reference Cheat Sheet
Basic Transformations
| JSON | TOON | Notes |
|---|---|---|
{"key": "value"} | key: value | Remove braces, quotes |
{"key": 123} | key: 123 | Numbers unchanged |
{"key": true} | key: true | Booleans unchanged |
{"key": null} | key: null | Null unchanged |
Nesting
| JSON | TOON |
|---|---|
{"a": {"b": "c"}} | a:<br> b: c |
Arrays
| JSON | TOON |
|---|---|
{"arr": [1, 2]} | arr: [1, 2] |
{"arr": [{"id": 1}]} | arr:<br> - id: 1 |
Validation Checklist
Before using your TOON file, verify:
- All braces removed
- Keys have no quotes
- Consistent indentation (2 spaces)
- Parent keys end with colons
- Arrays use correct syntax
- Values properly formatted
- No trailing commas
- Nested structures properly indented
Using Conversion Tools
For large files or production use, automated tools are recommended:
Benefits:
- ⚡ Instant conversion
- ✅ Error-free syntax
- 📊 Token count comparison
- 🔄 Batch processing
When to Use:
- Large JSON files (>100 lines)
- Production deployments
- Time-sensitive projects
- Team collaborations
Next Steps
Now that you know how to convert JSON to TOON:
- Practice with your own JSON files
- Measure your token savings
- Test with your LLM applications
- Deploy to production gradually
- Monitor your cost reductions
Conclusion
Converting JSON to TOON is straightforward:
- ✅ Remove curly braces
- ✅ Remove quotes from keys
- ✅ Clean up formatting
- ✅ Use indentation for nesting
- ✅ Handle arrays correctly
With practice, these conversions become second nature. Start small, validate your work, and scale up as you gain confidence.
Token savings of 30-60% await!
Ready to convert? Try our free online JSON to TOON converter and see your token savings instantly.