Skip to content

Commit 4fa8dc6

Browse files
committed
feat: Add sample generation scripts, extensive test files, new encoded samples, and update benchmark runner, ZON encoder, and decoder.
1 parent 29e258e commit 4fa8dc6

50 files changed

Lines changed: 10719 additions & 453 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

zon-format/CHANGELOG.md

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# Changelog
2+
3+
All notable changes to the ZON Format project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [1.0.1] - 2025-11-24
9+
10+
### Changed - "ClearText" Major Format Overhaul
11+
12+
#### Format Improvements
13+
- **Removed protocol overhead**: Eliminated `#Z:`, `|` pipes, and complex header markers
14+
- **YAML-like metadata**: Changed from `M=key="val"` to clean `key:val` syntax
15+
- **Clean @table syntax**: Replaced schema markers with readable `@tablename(count):cols`
16+
- **Aggressive quote removal**: Only quote when absolutely necessary (commas, control chars)
17+
- Spaces no longer trigger quoting: `Blue Lake Trail` instead of `"Blue Lake Trail"`
18+
- Colons allowed in values
19+
- **Compact array syntax**: `[item1,item2,item3]` with minimal inner quotes
20+
- **No spaces after separators**: Removed spaces after `:` and `,` for compactness
21+
22+
#### Performance
23+
- **31.9% compression** vs JSON (up from 27.4%)
24+
- **25.6% better** than TOON (up from 20.8%)
25+
- Tested on 318 records across 6 real-world datasets
26+
27+
#### New Features
28+
- Singleton bypass: 1-item lists flatten to metadata (`items.0.id:1`)
29+
- Pure list handling: Lists without wrapper use default `@data` table name
30+
- Boolean hard rule: Always explicit `T`/`F`, never inferred from empty cells
31+
32+
#### Documentation
33+
- Comprehensive README.md with visual comparisons
34+
- EXAMPLES.md with detailed symbol reference
35+
- Benchmark sample generation scripts
36+
- `/benchmarks/encoded_samples/` with `.json`, `.zon`, and `.toon` comparisons
37+
38+
### Fixed
39+
- Boolean preservation in roundtrip encoding/decoding
40+
- Array index handling in decoder unflatten logic
41+
- Pure list encoding/decoding (was returning empty string)
42+
43+
## [1.0.0] - 2025-11-23
44+
45+
### Added - Initial Release
46+
47+
#### Core Features
48+
- ZON v7.0 format with pipe-based protocol syntax
49+
- Compression rules: Range (R), Liquid (L), Solid (S), Pattern (P), Value (V)
50+
- Anchor-based row references
51+
- Global dictionary for repeated strings
52+
- CLI tool for encoding/decoding
53+
- Comprehensive test suite
54+
55+
#### Performance
56+
- ~27% average compression vs JSON
57+
- ~21% better than TOON on structured data
58+
59+
#### Package
60+
- Python 3.8+ support
61+
- PyPI distribution
62+
- Apache 2.0 license
63+
64+
---
65+
66+
## Upgrade Notes
67+
68+
### From 1.0.0 to 1.0.1
69+
70+
**⚠️ Breaking Change**: The encoded format has changed completely. Data encoded with v1.0.0 will **not** decode correctly with v1.0.1.
71+
72+
**Migration**: Re-encode your data with v1.0.1:
73+
74+
```python
75+
import zon
76+
77+
# Load your JSON data
78+
with open('data.json') as f:
79+
data = json.load(f)
80+
81+
# Encode with new format
82+
encoded = zon.encode(data)
83+
84+
# Decode works as before
85+
decoded = zon.decode(encoded)
86+
```
87+
88+
**Benefits**: The new format is much more readable and efficient. The migration is worth it for:
89+
- ✅ 4.5% additional compression
90+
- ✅ Zero protocol overhead
91+
- ✅ Better LLM readability
92+
- ✅ Cleaner visual appearance
93+
94+
---
95+
96+
## Links
97+
98+
- [PyPI](https://pypi.org/project/zon-format/)
99+
- [GitHub](https://github.com/ZON-Format/ZON)
100+
- [Examples](EXAMPLES.md)
101+
- [README](README.md)

zon-format/EXAMPLES.md

Lines changed: 291 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,291 @@
1+
# ZON Format Examples
2+
3+
This document provides detailed examples of ZON v8.0 encoding across different data types and structures.
4+
5+
## Table of Contents
6+
7+
- [Basic Examples](#basic-examples)
8+
- [Format Comparison](#format-comparison)
9+
- [Symbol Reference](#symbol-reference)
10+
- [Advanced Examples](#advanced-examples)
11+
12+
## Basic Examples
13+
14+
### Simple List
15+
16+
**JSON**:
17+
```json
18+
[
19+
{"id": 1, "name": "Alice"},
20+
{"id": 2, "name": "Bob"}
21+
]
22+
```
23+
24+
**ZON**:
25+
```
26+
@data(2):id,name
27+
1,Alice
28+
_,Bob
29+
```
30+
31+
- `@data(2)` → table with 2 rows
32+
- `_` → auto-increment (2 = 1 + 1)
33+
34+
---
35+
36+
### Nested Object
37+
38+
**JSON**:
39+
```json
40+
{
41+
"config": {
42+
"host": "localhost",
43+
"port": 5432
44+
},
45+
"users": [
46+
{"id": 1, "name": "test"}
47+
]
48+
}
49+
```
50+
51+
**ZON**:
52+
```
53+
config.host:localhost
54+
config.port:5432
55+
56+
@users(1):id,name
57+
1,test
58+
```
59+
60+
- Dot notation flattens nesting
61+
- Metadata separated from table with blank line
62+
63+
---
64+
65+
### Arrays in Metadata
66+
67+
**JSON**:
68+
```json
69+
{
70+
"tags": ["python", "data", "format"],
71+
"version": "1.0"
72+
}
73+
```
74+
75+
**ZON**:
76+
```
77+
tags:[python,data,format]
78+
version:1.0
79+
```
80+
81+
- No quotes in arrays unless needed
82+
- Compact `[item,item,item]` syntax
83+
84+
---
85+
86+
## Format Comparison
87+
88+
### Example: User Records
89+
90+
**JSON (201 bytes)**:
91+
```json
92+
[
93+
{"id":1,"name":"Alice","age":30,"active":true,"city":"NYC"},
94+
{"id":2,"name":"Bob","age":25,"active":false,"city":"LA"},
95+
{"id":3,"name":"Charlie","age":35,"active":true,"city":"NYC"}
96+
]
97+
```
98+
99+
**TOON (formatted, ~180 bytes)**:
100+
```
101+
users[3]{id,name,age,active,city}
102+
1,Alice,30,true,"NYC"
103+
2,Bob,25,false,"LA"
104+
3,Charlie,35,true,"NYC"
105+
```
106+
107+
**ZON (106 bytes - 47% smaller than JSON)**:
108+
```
109+
@data(3):active,age,city,id,name
110+
T,30,NYC,1,Alice
111+
F,25,LA,_,Bob
112+
T,35,^,_,Charlie
113+
```
114+
115+
**Why ZON wins**:
116+
- ✅ No quotes on simple strings
117+
-`T`/`F` instead of `true`/`false` (3 bytes saved per boolean)
118+
-`_` for auto-increment IDs
119+
-`^` for repeated values (NYC)
120+
- ✅ No spaces after delimiters
121+
122+
---
123+
124+
## Symbol Reference
125+
126+
### Metadata Symbols
127+
128+
| Symbol | Meaning | Example |
129+
|--------|---------|---------|
130+
| `:` | Key-value separator | `name:Alice` |
131+
| `.` | Nested object delimiter | `user.name:Alice` |
132+
| `[]` | Array | `tags:[a,b,c]` |
133+
| `,` | Array/table delimiter | No quotes around spaces |
134+
135+
### Table Symbols
136+
137+
| Symbol | Meaning | Example |
138+
|--------|---------|---------|
139+
| `@` | Table marker | `@users(10):id,name` |
140+
| `()` | Row count | `@data(5)` |
141+
| `:` | Header separator | `@table:col1,col2` |
142+
143+
### Compression Tokens
144+
145+
| Token | Meaning | Example | Output |
146+
|-------|---------|---------|--------|
147+
| `_` | Auto-increment | `1,_,_` | `1,2,3` |
148+
| `^` | Repeat previous | `red,^,blue` | `red,red,blue` |
149+
| `T` | Boolean true | `T` | `true` |
150+
| `F` | Boolean false | `F` | `false` |
151+
| `null` | Null value | `null` | `null` |
152+
153+
---
154+
155+
## Advanced Examples
156+
157+
### Complex Nested Data
158+
159+
**Input**:
160+
```json
161+
{
162+
"company": "Acme Inc",
163+
"employees": [
164+
{
165+
"id": 1,
166+
"name": "John Doe",
167+
"department": "Engineering",
168+
"skills": ["Python", "Go"],
169+
"active": true
170+
},
171+
{
172+
"id": 2,
173+
"name": "Jane Smith",
174+
"department": "Engineering",
175+
"skills": ["Java", "Kotlin"],
176+
"active": true
177+
}
178+
]
179+
}
180+
```
181+
182+
**ZON Output**:
183+
```
184+
company:Acme Inc
185+
186+
@employees(2):active,department,id,name,skills
187+
T,Engineering,1,John Doe,[Python,Go]
188+
^,^,_,Jane Smith,[Java,Kotlin]
189+
```
190+
191+
**Symbols explained**:
192+
- `company:Acme Inc` → metadata (no quotes needed)
193+
- `@employees(2)` → The table name and row count
194+
- `T` → Boolean true
195+
- `^` → Repeat "Engineering" and "T"
196+
- `_` → Auto-increment ID (2 = 1 + 1)
197+
- `[Python,Go]` → Inline array (no quotes)
198+
199+
---
200+
201+
### Repetitive Data
202+
203+
**Input**: Weather data with repeated locations
204+
205+
```json
206+
[
207+
{"date": "2024-01-01", "city": "NYC", "temp": 32},
208+
{"date": "2024-01-02", "city": "NYC", "temp": 35},
209+
{"date": "2024-01-03", "city": "NYC", "temp": 30},
210+
{"date": "2024-01-04", "city": "LA", "temp": 68}
211+
]
212+
```
213+
214+
**ZON**:
215+
```
216+
@data(4):city,date,temp
217+
NYC,2024-01-01,32
218+
^,2024-01-02,35
219+
^,2024-01-03,30
220+
LA,2024-01-04,68
221+
```
222+
223+
- `^` compresses 3 repeated "NYC" values
224+
- Saves ~12 bytes on city names alone
225+
226+
---
227+
228+
### Mixed Data Types
229+
230+
**Input**:
231+
```json
232+
{
233+
"user": "alice",
234+
"score": 95.5,
235+
"verified": true,
236+
"tags": ["premium", "early-adopter"],
237+
"metadata": null
238+
}
239+
```
240+
241+
**ZON**:
242+
```
243+
metadata:null
244+
score:95.5
245+
tags:[premium,early-adopter]
246+
user:alice
247+
verified:T
248+
```
249+
250+
- All types preserved correctly
251+
- Alphabetical sorting for consistency
252+
- No unnecessary quotes
253+
254+
---
255+
256+
## When to Quote Strings
257+
258+
ZON uses **minimal quoting** - quotes are only added when the value contains:
259+
- Comma `,` (the delimiter)
260+
- Newline, tab, or control characters
261+
- Brackets `[]` that could be confused with arrays
262+
- Quote character `"`
263+
264+
### Examples:
265+
266+
| Value | ZON Output | Quoted? | Reason |
267+
|-------|------------|---------|--------|
268+
| `Alice` | `Alice` | No | Simple alphanumeric |
269+
| `New York` | `New York` | No | **Spaces are fine!** |
270+
| `Hello: World` | `Hello: World` | No | **Colons are fine!** |
271+
| `data,value` | `"data,value"` | Yes | Contains comma |
272+
| `[test]` | `"[test]"` | Yes | Contains brackets |
273+
| `say "hi"` | `"say \"hi\""` | Yes | Contains quotes |
274+
275+
This is a major improvement over v7.0 which quoted anything with spaces or colons!
276+
277+
---
278+
279+
## Performance Tips
280+
281+
1. **Use sequential IDs**: Let `_` token handle auto-increment
282+
2. **Group similar data**: Repetition compression works best on sorted data
283+
3. **Flatten when possible**: Nested objects become dot-notation metadata
284+
4. **Avoid deep nesting in tables**: Tables should be flat records
285+
286+
---
287+
288+
## See Also
289+
290+
- [README.md](README.md) - Full documentation
291+
- [benchmarks/encoded_samples/](benchmarks/encoded_samples/) - Real-world examples

0 commit comments

Comments
 (0)