JSON to TOON Converter REST API
The JSON to TOON API provides a simple REST endpoint for converting between JSON and TOON (Token-Oriented Object Notation) formats. TOON achieves ~40% token reduction compared to JSON, making it ideal for LLM prompts and AI applications.
https://jsontotoon.io/api/v1
/v1/convert) requires an API key. Get your free API key here.Converts data between JSON and TOON formats in either direction.
| Parameter | Type | Required | Description |
|---|---|---|---|
input |
string | Required | The JSON string or TOON string to convert |
direction |
string | Required | Either "json_to_toon" or "toon_to_json" |
Success Response (200 OK):
{
"output": "<converted string>",
"direction": "json_to_toon"
}
Error Response (400 Bad Request):
{
"error": "Error message describing what went wrong"
}
curl -X POST https://jsontotoon.io/api/convert \
-H "Content-Type: application/json" \
-d '{
"input": "{\"name\": \"Alice\", \"age\": 30}",
"direction": "json_to_toon"
}'
const response = await fetch('https://jsontotoon.io/api/convert', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
input: JSON.stringify({ name: 'Alice', age: 30 }),
direction: 'json_to_toon'
})
});
const data = await response.json();
console.log(data.output);
// Output: name: Alice\nage: 30
import requests
import json
url = 'https://jsontotoon.io/api/convert'
payload = {
'input': json.dumps({'name': 'Alice', 'age': 30}),
'direction': 'json_to_toon'
}
response = requests.post(url, json=payload)
data = response.json()
print(data['output'])
# Output: name: Alice\nage: 30
package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
)
func main() {
url := "https://jsontotoon.io/api/convert"
payload := map[string]string{
"input": `{"name": "Alice", "age": 30}`,
"direction": "json_to_toon",
}
jsonData, _ := json.Marshal(payload)
resp, _ := http.Post(url, "application/json", bytes.NewBuffer(jsonData))
var result map[string]interface{}
json.NewDecoder(resp.Body).Decode(&result)
fmt.Println(result["output"])
// Output: name: Alice\nage: 30
}
curl -X POST https://jsontotoon.io/api/convert \
-H "Content-Type: application/json" \
-d '{
"input": "name: Alice\nage: 30",
"direction": "toon_to_json"
}'
const response = await fetch('https://jsontotoon.io/api/convert', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
input: 'name: Alice\nage: 30',
direction: 'toon_to_json'
})
});
const data = await response.json();
const jsonObj = JSON.parse(data.output);
console.log(jsonObj);
// Output: { name: 'Alice', age: 30 }
import requests
import json
url = 'https://jsontotoon.io/api/convert'
payload = {
'input': 'name: Alice\nage: 30',
'direction': 'toon_to_json'
}
response = requests.post(url, json=payload)
data = response.json()
json_obj = json.loads(data['output'])
print(json_obj)
# Output: {'name': 'Alice', 'age': 30}
package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
)
func main() {
url := "https://jsontotoon.io/api/convert"
payload := map[string]string{
"input": "name: Alice\\nage: 30",
"direction": "toon_to_json",
}
jsonData, _ := json.Marshal(payload)
resp, _ := http.Post(url, "application/json", bytes.NewBuffer(jsonData))
var result map[string]interface{}
json.NewDecoder(resp.Body).Decode(&result)
fmt.Println(result["output"])
// Output: {"name": "Alice", "age": 30}
}
Invalid JSON (400):
{
"error": "Invalid JSON: Expecting property name enclosed in double quotes"
}
Invalid Direction (400):
{
"error": "Invalid direction: wrong_value. Use \"json_to_toon\" or \"toon_to_json\""
}
Missing Input (400):
{
"error": "Missing required field: input"
}
TOON Parsing Error (400):
{
"error": "TOON parsing error: Invalid TOON syntax at line 2"
}
TOON (Token-Oriented Object Notation) is a compact, human-readable format designed specifically for Large Language Model inputs. It combines YAML-style indentation with CSV-like tabular layouts for uniform arrays, optimizing for the way LLMs actually tokenize text.
When working with LLM APIs like Claude, GPT-4, or Gemini, you pay per token. JSON is great for machines, but it's incredibly wasteful for tokens—all those curly braces, quotes, and commas add up fast. For applications sending large datasets in prompts (think RAG systems, data analysis agents, or multi-shot examples), token costs can spiral quickly.
TOON was created to solve this exact problem. By removing unnecessary syntax while maintaining structure and readability, it achieves significant token reduction without sacrificing data fidelity.
JSON to TOON conversion example:
[
{"name": "Alice", "age": 30, "city": "NYC"},
{"name": "Bob", "age": 25, "city": "LA"},
{"name": "Carol", "age": 35, "city": "Chicago"}
]
name, age, city
Alice, 30, NYC
Bob, 25, LA
Carol, 35, Chicago
For uniform arrays (like database rows or API responses), TOON uses a CSV-style header format. For nested objects, it uses YAML-style indentation. The format is deterministic—the same JSON always produces the same TOON output, and round-trip conversion is lossless.
TOON uses indentation-based nesting (like YAML) for objects and a header-based format (like CSV) for arrays of uniform objects. The parser is deterministic and handles edge cases like nested arrays, mixed-type arrays, null values, and special characters. Unlike YAML, TOON has a much simpler specification focused exclusively on JSON compatibility—no weird type coercion or ambiguous syntax.
Learn more: TOON Format Specification
TOON Specification: github.com/toon-format/toon