Core Syntax
Scalars
GLYPH supports six primitive types:GLYPH uses
_ for null (not null), t/f for booleans (not true/false), and allows bare strings when safe.Collections
- Lists
- Maps
- Structs
Lists use space-separated elements:
No commas between elements
JSON vs GLYPH
Here’s a side-by-side comparison:Syntax Differences
| Feature | JSON | GLYPH | Tokens Saved |
|---|---|---|---|
| Key quotes | "key": | key= | 2 per key |
| Separator | : | = | Same |
| Delimiter | , | space | 1 per field |
| Booleans | true/false | t/f | 2-3 per value |
| Null | null | _ | 3 per value |
Bare String Rules
A string can be written without quotes if:- Non-empty
- First character: Unicode letter or
_ - Remaining characters: Unicode letter, digit,
_,-,.,/ - Not a reserved word:
t,f,true,false,null,none,nil
Canonical Form
GLYPH has a deterministic canonical form, crucial for hashing and state verification.Float Formatting
- Rules
- Examples
- Zero: Always
0(not-0or0.0) - Threshold: Use exponent when
exp < -4orexp >= 15 - Format: 2-digit minimum exponent (
1e-06, not1e-6) - Rejected: NaN and Infinity (not JSON-compatible)
Key Ordering
Map keys are sorted by bytewise UTF-8 comparison:A (0x41) < _ (0x5F) < a (0x61)
This ensures the same data always produces the same output across all implementations (Go, Python, JavaScript, Rust, C).
Duplicate Keys
Last-wins policy: When duplicate keys exist, the last value is used.Extended Types
GLYPH includes types beyond JSON’s capabilities:- References
- Timestamps
- Bytes
Typed references with namespace prefixes:Format:
^<prefix>:<value>LOOSE MODE
LOOSE MODE is GLYPH’s schema-optional subset, designed as a drop-in JSON replacement.Design Goals
From the LOOSE_MODE_SPEC:- Drop-in JSON replacement - Any valid JSON is valid input
- Deterministic canonical form - Same data → same output
- Cross-language parity - Go, JS, Python produce identical output
- Token efficiency - More compact than JSON
Key Features
JSON Compatible
Accept any JSON, emit valid JSON. Perfect round-trip.
Deterministic
SHA-256 hashing for state verification and conflict detection.
Compact
40-60% fewer tokens than JSON for typical data.
Cross-language
Byte-identical output across all implementations.
Usage Examples
Type System
GLYPH supports constraints for validation:Integer Constraints
String Constraints
Enum Constraints
Real-World Example
Here’s a complex nested structure:Summary
GLYPH Format Benefits
- 40-60% fewer tokens than JSON
- Deterministic canonical form for hashing
- Human-readable text format
- Cross-language compatible (Go, Python, JS, Rust, C)
- Drop-in JSON replacement (LOOSE MODE)
- Rich type system with constraints
Next Steps
Token Savings
Learn how GLYPH reduces token usage
Streaming Validation
Validate as tokens stream from LLMs
Tabular Mode
Compress homogeneous lists automatically
LOOSE MODE Spec
Complete technical specification