How do I convert JSON to TOON format?
Converting JSON to TOON format involves transforming the hierarchical structure while removing syntactic overhead.
Basic conversion rules:
- Remove all quotation marks from keys and string values unless they contain colons, newlines, or start with whitespace
- Remove opening and closing braces
{}for objects - Remove opening and closing brackets
[]for arrays - Use tab characters (or spaces) for indentation to represent nesting levels
- Keep colons between keys and values
- Use newlines to separate items instead of commas
- For arrays, list items on separate lines at the same indentation level, optionally with a dash prefix for clarity
Example:
JSON: {"user": {"name": "Alice", "age": 30, "tags": ["developer", "scraper"]}}
Converts to TOON:
user:
name: Alice
age: 30
tags:
developer
scraper
Special cases:
- Numbers and booleans remain unchanged
- Null values can be represented as
nullor omitted - Empty objects become just the key with a colon
- Strings with special characters (colons, newlines, leading/trailing spaces) should keep quotes
- Arrays of objects follow the same indentation pattern as nested objects
You can use our JSON to TOON converter tool which automatically handles these transformations, shows token count comparisons, and validates the output. For programmatic conversion, implement a recursive parser that walks the JSON structure and builds TOON output with proper indentation.