
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
jsonify-toonify
Advanced tools
This package provides utility methods to convert from json to toon and vice versa.
A lightweight TypeScript library for converting between JSON and TOON formats. TOON is a compact, token-efficient data format that's perfect for scenarios where you need to minimize data size while maintaining readability.
npm install jsonify-toonify
import { jsonToToon, toonToJson } from 'jsonify-toonify';
// Convert JSON to TOON
const json = { sku: "A1", qty: 2, price: 9.99 };
const toon = jsonToToon(json);
console.log(toon);
// Output: [1]{sku,qty,price}:
// A1,2,9.99
// Convert TOON back to JSON
const backToJson = toonToJson(toon);
console.log(backToJson);
// Output: { sku: 'A1', qty: 2, price: 9.99 }
jsonToToon(input: unknown): stringConverts a JSON value (object, array, or primitive) to TOON format.
Parameters:
input - Any JSON-serializable value (object, array, number, string, boolean, null, or a JSON string)Returns: A string in TOON format
Examples:
// Simple object
jsonToToon({ name: "John", age: 30 });
// [1]{name,age}:
// John,30
// Array of objects
jsonToToon([
{ id: 1, name: "Alice" },
{ id: 2, name: "Bob" }
]);
// [2]{id,name}:
// 1,Alice
// 2,Bob
// Array of primitives
jsonToToon([1, 2, 3]);
// [3]{value}:
// 1
// 2
// 3
// Primitives
jsonToToon(42); // "42"
jsonToToon(true); // "true"
jsonToToon(null); // "null"
// JSON string input
jsonToToon('{"a": 1}');
// [1]{a}:
// 1
toonToJson(toon: string): anyConverts a TOON format string back to JSON.
Parameters:
toon - A string in TOON formatReturns: The original JSON value (object, array, or primitive)
Examples:
// Simple object
toonToJson('[1]{name,age}:\nJohn,30');
// { name: 'John', age: 30 }
// Array of objects
toonToJson('[2]{id,name}:\n1,Alice\n2,Bob');
// [{ id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }]
// Array of primitives
toonToJson('[3]{value}:\n1\n2\n3');
// [1, 2, 3]
// Primitives
toonToJson('42'); // 42
toonToJson('true'); // true
toonToJson('null'); // null
The TOON format is designed to be compact and human-readable:
Objects are represented as single-row tables:
[1]{key1,key2,key3}:
value1,value2,value3
Arrays of objects become multi-row tables:
[2]{id,name}:
1,Alice
2,Bob
Primitive arrays use a special value header:
[3]{value}:
1
2
3
Nested objects are JSON-stringified within the TOON format:
[1]{product,qty}:
{"id":"X1","price":100},3
[0]{value}: // Empty array
[1]{}: // Empty object
const products = [
{ sku: "A1", name: "Widget", price: 9.99, stock: 100 },
{ sku: "B2", name: "Gadget", price: 19.99, stock: 50 }
];
const toon = jsonToToon(products);
console.log(toon);
// [2]{sku,name,price,stock}:
// A1,Widget,9.99,100
// B2,Gadget,19.99,50
const config = {
apiUrl: "https://api.example.com",
timeout: 5000,
retries: 3,
enabled: true
};
const toon = jsonToToon(config);
console.log(toon);
// [1]{apiUrl,timeout,retries,enabled}:
// https://api.example.com,5000,3,true
const original = { users: [{ id: 1, name: "Alice" }, { id: 2, name: "Bob" }] };
// Convert to TOON
const toon = jsonToToon(original);
// Convert back to JSON
const restored = toonToJson(toon);
// They should be equal
console.log(JSON.stringify(original) === JSON.stringify(restored)); // true
try {
// Invalid JSON string
jsonToToon('{invalid json}');
} catch (error) {
console.error(error.message); // "Invalid JSON string"
}
Full TypeScript definitions are included:
import { jsonToToon, toonToJson } from 'jsonify-toonify';
const data: { id: number; name: string }[] = [
{ id: 1, name: "Alice" }
];
const toon: string = jsonToToon(data);
const restored: typeof data = toonToJson(toon);
Works in all modern browsers and Node.js environments (Node.js 12+).
Contributions are welcome! Please feel free to submit a Pull Request.
MIT
FAQs
This package provides utility methods to convert from json to toon and vice versa.
We found that jsonify-toonify demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.