Overview
GLYPH-Loose is the schema-optional subset of GLYPH. It provides a deterministic canonical representation for JSON-like data, making it ideal for:- Hashing and fingerprinting
- Caching with stable keys
- Cross-language interoperability
- Drop-in JSON replacement
Design Goals
Drop-in JSON Replacement
Any valid JSON is valid GLYPH-Loose input
Deterministic Canonical Form
Same data always produces identical output
Cross-Language Parity
Go, JS, and Python implementations produce byte-identical results
Compact
More token-efficient than JSON for LLM contexts
Canonical Rules
Scalars
| Type | Canonical Form | Examples |
|---|---|---|
| null | _ | _ (accepts ∅, null on input) |
| bool | t / f | t, f |
| int | Decimal, no leading zeros | 0, 42, -100 |
| float | Shortest roundtrip, e (not E) | 3.14, 1e-06, 1e+15 |
| string | Bare if safe, else quoted | hello, "hello world" |
Float Formatting
- Zero: Always
0(not-0, not0.0) - Negative zero: Canonicalizes to
0 - Exponent threshold: Use exponential when
exp < -4orexp >= 15 - Exponent format: 2-digit minimum (
1e-06, not1e-6) - NaN/Infinity: Rejected with error (not JSON-compatible)
String Bare-Safe Rule
A string is “bare-safe” (unquoted) if:- Non-empty
- First character: Unicode letter or
_ - Remaining characters: Unicode letter, digit,
_,-,.,/ - Not a reserved word:
t,f,true,false,null,none,nil
Containers
| Type | Canonical Form |
|---|---|
| list | [ + space-separated elements + ] |
| map | { + sorted key=value pairs + } |
Key Ordering
Map keys are sorted by bytewise UTF-8 comparison of their canonical string form.A (0x41) < _ (0x5F) < a (0x61) < …
Duplicate Keys
Last-wins policy: When a JSON object has duplicate keys, the last value is used.JSON Bridge
Input (JSON → GLYPH)
- Accepts any valid JSON
- Rejects NaN/Infinity (returns error)
- Integers within ±2^53 become
int, others becomefloat
Output (GLYPH → JSON)
- IDs become
"^prefix:value"strings - Times become ISO-8601 strings
- Bytes become base64 strings
Extended Mode
WithBridgeOpts{Extended: true}:
- Times become
{"$glyph":"time","value":"..."} - IDs become
{"$glyph":"id","value":"^..."} - Bytes become
{"$glyph":"bytes","base64":"..."}
CLI Usage
When to Use Loose Mode
Drop-in JSON Replacement
Drop-in JSON Replacement
When you need to reduce token usage for LLM communication without changing your data model.Use case: Serializing API responses, agent state, or tool call results.
State Fingerprinting
State Fingerprinting
When you need deterministic hashing for caching, versioning, or integrity verification.Use case: Agent checkpoints, distributed state sync, optimistic concurrency control.
Cross-Language Interop
Cross-Language Interop
When you need identical serialization across Go, Python, and JavaScript.Use case: Multi-language microservices, polyglot agent systems.
Human-Readable Logs
Human-Readable Logs
When you want compact, readable logs without JSON noise.Use case: Debugging, audit trails, human review of agent decisions.
Conformance Testing
The test corpus attestdata/loose_json/ contains 50 cases covering:
- Deep nesting (10-20 levels)
- Unicode (surrogates, CJK, emoji)
- Edge numbers (boundaries, precision)
- Key ordering (stability, unicode)
- Duplicate keys
- Reserved words
- Control characters
testdata/loose_json/golden/ anchor expected canonical output.
Cross-implementation tests verify Go, JS, and Python produce byte-identical canonical forms.
Upgrade Path
GLYPH-Loose is the foundation. When you need schema features:- Add a schema → enables packed encoding, FID-based parsing
- Use
@openstructs → collect unknown fields safely - Use
map<K,V>→ validate dynamic keys - Use patches → efficient incremental updates
Next Steps
GS1 Streaming
Learn about frame-based streaming with integrity checks
Patches
Explore incremental state updates with base verification
Fingerprinting
Understand SHA-256 state hashing for verification
API Reference
Explore language-specific APIs