A zero-dependency Python micro-tool that converts JSON into Token-Oriented Object Notation (TOON). TOON reduces LLM token usage by up to 60% by eliminating repetitive JSON keys in uniform arrays and rendering them as compact CSV-style tables.
from json_to_toon_lite import convert_json_to_toon
json_data = """
{
"location": "Berlin",
"alerts": ["frost", "wind"],
"forecast": [
{"day": "Mon", "temp": -2, "condition": "snow"},
{"day": "Tue", "temp": 1, "condition": "cloudy"}
]
}
"""
print(convert_json_to_toon(json_data))Output: (Massive Token Savings!)
location: Berlin
alerts[2]: frost,wind
forecast[2]{day,temp,condition}:
Mon,-2,snow
Tue,1,cloudy