toon-to-any
v2.0.8
Published
JSON ↔ TOON converter with full recursive nested support and high-performance streaming.
Downloads
80
Maintainers
Readme
toon-to-any
⚡ Make your API responses 10× faster by converting heavy JSON data into a compact TOON format — ideal for large datasets, real-time dashboards, and high-traffic backends.
toon-to-any is a fast and lightweight transformer that converts deep/nested JSON structures into a compact, columnar TOON format, with full support for:
- ✔ deeply nested objects
- ✔ arrays of objects
- ✔ arrays of primitives
- ✔ mixed/nested array/object structures
- ✔ streaming large MongoDB/SQL datasets
- ✔ full round-trip: JSON → TOON → JSON
Designed for high-performance backend apps and clients needing lightweight, predictable structured data exchange.
Maintained by Truncate Technologies Pvt. Ltd.
🌐 https://www.truncate.in
🚀 Why use toon-to-any?
✅ 1. Make your API significantly faster
- Reduces JSON payload size by up to 80%
- Sends columnar TOON format instead of large repetitive JSON
- Clients reconstruct full JSON instantly
Perfect for APIs returning thousands to millions of rows.
✅ 2. Full recursive support
Automatically converts nested structures at ANY depth:
object → toon
array of objects → toon
nested arrays → toon
deeply mixed JSON → recursive toonFully reversible:
toon → original JSON (lossless)✅ 3. Stream massive datasets
MongoDB → cursor → TOON rows → client
No memory spikes. Suitable for millions of records.
✅ 4. Optimized for Node.js + React
Backend sends small TOON payload → frontend expands to JSON.
✅ 5. Zero dependencies + full TypeScript support
Lightweight, fast, production-ready.
📦 Install
npm install toon-to-any⚡ CLI Usage
toon-to-any input.json output.toon.json🔄 JSON → TOON
import { jsonToToon } from "toon-to-any";
const toon = jsonToToon(data);🔁 TOON → JSON
import { toonToJson } from "toon-to-any";
const arr = toonToJson(toon);🌊 Streaming (ideal for huge datasets)
import { createToonStream } from "toon-to-any";
db.stream().pipe(createToonStream(["id","name"])).pipe(res);🍃 MongoDB → Full Recursive TOON
import { jsonToToon } from "toon-to-any";
app.get("/api/products/toon", async (req, res) => {
const docs = await db.collection("products").find().toArray();
const toon = jsonToToon(docs);
res.json(toon);
});All nested fields (categories, variants, specs, images, etc.) are automatically TOON-converted.
🧪 Client-Side Example — TOON → JSON (React)
async function fetchProducts() {
const res = await fetch("/api/products/toon");
const toon = await res.json();
const data = toonToJson(toon);
setProducts(data);
}💡 When Should You Use toon-to-any?
Use this when:
- handling large JSON arrays (10k–1M rows)
- needing high-performance APIs
- wanting faster network responses
- reducing payload size matters
- exporting to BI tools / dashboards
- syncing large datasets between backend ↔ frontend
- looking for a simple alternative to Protobuf/Avro/MessagePack
📈 Performance Notes
| Operation | Speed | Notes | |------------------|-------|-------| | JSON → TOON | ⚡ Fast | No schema needed | | TOON → JSON | ⚡ Fast | Great for UI rendering | | Streaming | 🚀 Extreme | Perfect for MongoDB cursor streams | | Nested JSON | ✔ Unlimited depth | Fully supported |
Typical compression:
- 30–60% smaller for flat arrays
- 50–80% smaller for deeply nested payloads
- O(1) memory usage when streaming
🤝 Maintained By
Truncate Technologies Pvt. Ltd.
Enterprise Software & AI Solutions
🌐 https://www.truncate.in
📧 [email protected]
📄 License
MIT © Truncate Technologies Pvt. Ltd.
