Back

API Documentation

v1.0

Introduction

ToonUse provides a high-performance API to convert standard JSON data into Token-Oriented Object Notation (TOON). This format is optimized for Large Language Models, reducing token usage by 30-60% while maintaining data integrity.

1Authentication

Authenticate your requests using an API Key. You can generate one in your Profile Dashboard.

Authentication Header

X-API-Key: tk_your_api_key_here

2Endpoints

Convert JSON to TOON

POST/convert/json-to-toon

Accepts a JSON object or array and returns the compact TOON string.

Request Body Parameters

ParameterTypeRequiredDescription
dataObject | ArrayYesThe JSON object or array to be converted.
structuredBooleanNoDefault: false. If set to true, uses advanced structural compression for better token savings on complex nested data.
Request Bodyapplication/json
{
  "data": {
    "users": [
      { "id": 1, "name": "Alice" },
      { "id": 2, "name": "Bob" }
    ]
  },
  "structured": true  // Optional: Set to true for structured TOON format
}
Response200 OK
{
  "result": "users[2]{id,name}:\n1,Alice\n2,Bob",
  "tokens_saved": 45.2,
  "original_size": 85,
  "new_size": 46
}

Convert TOON to JSON

POST/convert/toon-to-json

Reconstructs the original JSON structure from a TOON string.

Request Body Parameters

ParameterTypeRequiredDescription
dataStringYesThe TOON format string to be converted back to JSON.
Request Bodyapplication/json
{
  "data": "users[2]{id,name}:\n1,Alice\n2,Bob"
}
Response200 OK
{
  "result": {
    "users": [
      { "id": 1, "name": "Alice" },
      { "id": 2, "name": "Bob" }
    ]
  },
  "tokens_saved": 0,
  "original_size": 46,
  "new_size": 85
}

3Code Examples

JSON to TOON

cURL

curl -X POST "https://api.toonuse.com/convert/json-to-toon" \
  -H "Content-Type: application/json" \
  -H "X-API-Key: tk_your_key" \
  -d '{"data": {"hello": "world"}, "structured": true}'

Python (requests)

import requests

url = "https://api.toonuse.com/convert/json-to-toon"
headers = {
    "X-API-Key": "tk_your_key",
    "Content-Type": "application/json"
}
data = {
    "data": {
        "users": [{"id": 1, "name": "Alice"}]
    },
    "structured": true
}

response = requests.post(url, json=data)
print(response.json())

JavaScript (Node.js)

const axios = require('axios');

async function convert() {
  const response = await axios.post(
    'https://api.toonuse.com/convert/json-to-toon',
    {
      data: { users: [{ id: 1, name: 'Alice' }] },
      structured: true
    },
    {
      headers: { 'X-API-Key': 'tk_your_key' }
    }
  );

  console.log(response.data);
}

convert();

TOON to JSON

cURL

curl -X POST "https://api.toonuse.com/convert/toon-to-json" \
  -H "Content-Type: application/json" \
  -H "X-API-Key: tk_your_key" \
  -d '{"data": "users[2]{id,name}:\n1,Alice\n2,Bob"}'

Python (requests)

import requests

url = "https://api.toonuse.com/convert/toon-to-json"
headers = {
    "X-API-Key": "tk_your_key",
    "Content-Type": "application/json"
}
data = {
    "data": "users[2]{id,name}:\n1,Alice\n2,Bob"
}

response = requests.post(url, json=data)
print(response.json())

JavaScript (Node.js)

const axios = require('axios');

async function convertBack() {
  const response = await axios.post(
    'https://api.toonuse.com/convert/toon-to-json',
    {
      data: "users[2]{id,name}:\n1,Alice\n2,Bob"
    },
    {
      headers: { 'X-API-Key': 'tk_your_key' }
    }
  );

  console.log(response.data);
}

convertBack();