JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 449
  • Score
    100M100P100Q95851F
  • License MIT

Zero Overhead Notation v1.0.1 - Human-readable data format with 30%+ compression over JSON

Package Exports

  • zon-format
  • zon-format/dist/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (zon-format) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

ZON Format v1.0.1 - TypeScript/JavaScript

Zero Overhead Notation - A human-readable data serialization format optimized for LLM token efficiency, JSON for LLMs.

npm version TypeScript License

๐Ÿš€ 14% better compression than TOON | ๐Ÿ“Š 30-67% compression vs JSON | ๐Ÿ” 100% Human Readable


๐Ÿ“š Table of Contents


๐Ÿš€ What is ZON?

ZON is a smart compression format designed specifically for transmitting structured data to Large Language Models. Unlike traditional compression (which creates binary data), ZON remains 100% human-readable while dramatically reducing token usage.

Why ZON?

Problem Solution
๐Ÿ’ธ High LLM costs from verbose JSON ZON reduces tokens by 30-67%
๐Ÿ” Binary formats aren't debuggable ZON is plain text - you can read it!
๐ŸŽฏ One-size-fits-all compression ZON auto-selects optimal strategy per column

Key Features

  • โœ… Entropy Tournament: Auto-selects best compression strategy per column
  • โœ… 100% Safe: Guaranteed lossless reconstruction
  • โœ… Zero Configuration: Works out of the box
  • โœ… TypeScript Support: Full type definitions included

๐Ÿ“Š Benchmarks

ZON vs TOON vs JSON (Token Efficiency)

We benchmarked ZON against TOON and JSON using the GPT-5 o200k_base tokenizer across 7 different dataset types.

๐Ÿ† ZON won on ALL 7 datasets.

Dataset Type ZON Tokens vs TOON vs JSON (formatted) vs JSON (compact)
Nested Structures 228 ๐Ÿ‘‘ -16.7% -57.7% -28.3%
Uniform Tabular 154 ๐Ÿ‘‘ -6.5% -67.4% -41.2%
Mixed Structures 125 ๐Ÿ‘‘ -8.8% -62.8% -38.7%
Deeply Nested 113 ๐Ÿ‘‘ -24.2% -51.1% -8.9%
Semi-uniform Logs 287 ๐Ÿ‘‘ -26.2% -40.2% -9.5%

Negative percentage means fewer tokens (better).

Summary:

  • ZON is 13.8% more efficient than TOON on average
  • ZON is 56.9% more efficient than JSON (formatted)
  • ZON is 27.5% more efficient than JSON (compact)

View full benchmark results


โšก Quick Start

import { encode, decode } from 'zon-format';

// Your data
const users = {
  context: {
    task: "Our favorite hikes together",
    location: "Boulder",
    season: "spring_2025"
  },
  friends: ["ana", "luis", "sam"],
  hikes: [
    {
      id: 1,
      name: "Blue Lake Trail",
      distanceKm: 7.5,
      elevationGain: 320,
      companion: "ana",
      wasSunny: true
    },
    {
      id: 2,
      name: "Ridge Overlook",
      distanceKm: 9.2,
      elevationGain: 540,
      companion: "luis",
      wasSunny: false
    },
    {
      id: 3,
      name: "Wildflower Loop",
      distanceKm: 5.1,
      elevationGain: 180,
      companion: "sam",
      wasSunny: true
    }
  ]
};

// Encode (compress)
const compressed = encode(users);
console.log(compressed);

// Decode (decompress)
const original = decode(compressed);
console.log(original); // Exact match!

Output (ZON format - 96 tokens, 264 bytes):

context:"{task:Our favorite hikes together,location:Boulder,season:spring_2025}"
friends:"[ana,luis,sam]"

@hikes(3):companion,distanceKm,elevationGain,id,name,wasSunny
ana,7.5,320,1,Blue Lake Trail,T
luis,9.2,540,2,Ridge Overlook,F
sam,5.1,180,3,Wildflower Loop,T

vs JSON (compact - 139 tokens, 451 bytes)


๐Ÿ“ฆ Installation

From npm

npm install zon-format

From yarn

yarn add zon-format

Verify Installation

import { encode, decode } from 'zon-format';

const data = { message: "Hello ZON!" };
const encoded = encode(data);
console.log(encoded); // message:Hello ZON!

const decoded = decode(encoded);
console.log(decoded); // { message: "Hello ZON!" }

๐Ÿ“š API Reference

encode(data, anchorInterval?)

Encodes a JavaScript object or array into a ZON-formatted string.

Parameters:

  • data (any): The input data to encode. Must be JSON-serializable (object, array, string, number, boolean, null).
  • anchorInterval (number, optional): Legacy parameter, defaults to 50. Not used in v1.0.1.

Returns:

  • string: The ZON-encoded string.

Example:

import { encode } from 'zon-format';

const data = { id: 1, name: "Alice" };
const zonStr = encode(data);
console.log(zonStr);
// Output: id:1
//         name:Alice

decode(zonStr)

Decodes a ZON-formatted string back into a JavaScript object or array.

Parameters:

  • zonStr (string): The ZON-encoded string to decode.

Returns:

  • any: The decoded JavaScript object or array.

Example:

import { decode } from 'zon-format';

const zonStr = `id:1
name:Alice`;

const data = decode(zonStr);
console.log(data); // { id: 1, name: "Alice" }

๐Ÿค– Examples

Basic Usage

import { encode, decode } from 'zon-format';

// Simple object
const user = { name: "Alice", age: 30, active: true };
const encoded = encode(user);
const decoded = decode(encoded);
// decoded === { name: "Alice", age: 30, active: true }

Array of Objects (Table Format)

import { encode, decode } from 'zon-format';

const products = [
  { id: 1, name: "Laptop", price: 999, inStock: true },
  { id: 2, name: "Mouse", price: 29, inStock: true },
  { id: 3, name: "Keyboard", price: 79, inStock: false }
];

const encoded = encode(products);
console.log(encoded);
// Output:
// @data(3):id,inStock,name,price
// 1,T,Laptop,999
// 2,T,Mouse,29
// 3,F,Keyboard,79

const decoded = decode(encoded);
// decoded === products (exact match)

Mixed Metadata and Table

import { encode, decode } from 'zon-format';

const report = {
  title: "Q1 Sales Report",
  year: 2024,
  quarter: 1,
  sales: [
    { month: "Jan", revenue: 50000, expenses: 30000 },
    { month: "Feb", revenue: 55000, expenses: 32000 },
    { month: "Mar", revenue: 60000, expenses: 35000 }
  ]
};

const encoded = encode(report);
const decoded = decode(encoded);
// Perfect reconstruction

Nested Objects

import { encode, decode } from 'zon-format';

const config = {
  app: {
    name: "MyApp",
    version: "1.0.0",
    features: {
      authentication: true,
      logging: true,
      caching: false
    }
  }
};

const encoded = encode(config);
const decoded = decode(encoded);
// Nested structure preserved

LLM Integration Example

import { encode } from 'zon-format';
import OpenAI from 'openai';

const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });

// Prepare data
const users = [
  { id: 1, name: "Alice", purchases: 15, total: 1500 },
  { id: 2, name: "Bob", purchases: 8, total: 800 },
  // ... 100 more users
];

// Compress with ZON (saves tokens = saves money!)
const zonData = encode(users);

// Use in prompt
const response = await openai.chat.completions.create({
  model: "gpt-4",
  messages: [
    {
      role: "system",
      content: "You will receive data in ZON format. Decode mentally and analyze."
    },
    {
      role: "user",
      content: `Analyze this user data:\n\n${zonData}\n\nWhat's the average purchase total?`
    }
  ]
});

console.log(response.choices[0].message.content);
// Cost Savings: ~30-40% fewer tokens vs JSON!

๐Ÿ“– Format Reference

Metadata (YAML-like)

key:value
nested.key:value
list:[item1,item2,item3]
  • No spaces after : for compactness
  • Dot notation for nested objects
  • Minimal quoting (only when necessary)

Tables (@table syntax)

@tablename(count):col1,col2,col3
val1,val2,val3
val1,val2,val3
  • @ marks table start
  • (count) shows row count
  • Columns separated by commas (no spaces)

Compression Tokens

Token Meaning Example
T Boolean true T instead of true
F Boolean false F instead of false

Type Handling

  • Booleans: Encoded as T or F
  • Null: Encoded as null
  • Numbers: Preserved with exact representation
  • Floats: Always include decimal point (e.g., 42.0)
  • Strings: Minimal quoting, quoted only when needed
  • Objects/Arrays: Inline ZON format {key:val} or [val1,val2]

๐Ÿงช Testing

Run tests:

npm test

Build:

npm run build

๐Ÿค Contributing

This is a port of the original Python implementation. Contributions are welcome!

  1. Fork the repository
  2. Create a feature branch
  3. Add tests for new features
  4. Submit a pull request

๐Ÿ“„ License

MIT License

Copyright (c) 2025 Roni Bhakta. All Rights Reserved.

See LICENSE for full terms.


๐Ÿ™ Acknowledgments

  • Original Python implementation: ZON-Format/ZON
  • Inspired by TOON format for LLM token efficiency
  • TypeScript port maintains 100% compatibility with Python version

โœ‰๏ธ Support


Made with โค๏ธ for the LLM community

ZON v1.0.1 - Compression that scales with complexity