Specification ID
Spec ID:glyph-loose-1.0.0Date: 2026-01-13
Status: Stable (Frozen) Canonical output for any input in the test corpus is frozen and will not change.
Overview
GLYPH-Loose is the schema-optional subset of GLYPH. It provides a deterministic canonical representation for JSON-like data, suitable for hashing, caching, and cross-language interoperability.Design Goals
- Drop-in JSON replacement - Any valid JSON is valid GLYPH-Loose input
- Deterministic canonical form - Same data always produces same output
- Cross-language parity - Go, JS, and Python implementations produce identical output
- 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.Type Mappings
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)
- Produces valid JSON
- IDs become
"^prefix:value"strings - Times become ISO-8601 strings
- Bytes become base64 strings
Extended Mode
WithBridgeOpts{Extended: true}:
CLI Usage
Schema Extensions
@open Structs
The@open annotation allows a struct type to accept fields not defined in the schema.
Schema Definition:
| Struct Type | Unknown Field | Validation Result |
|---|---|---|
| Closed (default) | Present | Error: unknown_field |
@open | Present | Pass (warning logged) |
@open + Strict | Present | Error: unknown_field |
map<K,V> Validation
Map values are validated against the specified value type:Auto-Tabular Mode
Auto-Tabular mode provides compact representation for homogeneous lists of objects.Syntax
- Header:
@tab _followed by sorted column names in brackets - Rows: Pipe-delimited cells, one row per line
- Footer:
@endmarker
Enabling Auto-Tabular
Eligibility Criteria
A list qualifies for tabular emission when:- Contains ≥
MinRowselements (default: 3) - All elements are maps or structs
- Total column count ≤
MaxCols(default: 20) - When
AllowMissing=false, all rows must have identical keys
Options Reference
| Option | Type | Default | Description |
|---|---|---|---|
AutoTabular | bool | true | Enable auto-tabular detection |
MinRows | int | 3 | Minimum rows to trigger tabular |
MaxCols | int | 20 | Maximum columns allowed |
AllowMissing | bool | true | Allow rows with missing keys |
NullStyle | NullStyle | underscore | symbol for ∅, underscore for _ |
SchemaRef | string | "" | Schema hash/id for @schema header |
KeyDict | []string | nil | Key dictionary for compact keys |
UseCompactKeys | bool | false | Emit #N instead of field names |
Schema Context & Key Dictionaries
For repeated structured outputs, schema contexts enable significant token savings through compact key encoding.Schema Directive Format
Inline schema (self-contained):Usage
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