Skip to content
mossbenchlabPublic

About

An AI-first data format: one canonical byte encoding, machine-readable errors, exact decimals, lossless JSON bridge. Spec v1.0 with reference implementations in Python, TypeScript, Rust, and Go.

Topics

Resources

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Weft 1.0

Weft is an AI-first textual data format — a JSON alternative designed for documents that language models read, write, sign, and round-trip. It pairs with the Lattice project.

{:name "weft"
 :version "1.0.1"
 :precise 0.1m            ; Decimal — exact, not binary float
 :big 9007199254740993n   ; BigInt — no silent precision loss
 :when #2026-11-02T12:00:00+09:00
 :tags [:data :ai]
 :payload b"base64:aGVsbG8="}

Why Weft

  • Types JSON lacks. BigInt, Decimal, Binary, DateTime, Symbol, Keyword, Sexpr, and typed values (::T) are first-class — no ad-hoc string conventions.
  • One canonical form (SPEC §7.3). Strict canonical output is byte-identical across implementations — sort order, float shortest round-trip (tie-break verified against CPython/V8/Go behavior), escape set, everything pinned. Canonical bytes are safe to hash and sign.
  • Lossless JSON bridge (SPEC §11.2). Every Weft document maps to plain JSON and back without losing a bit — including the 1 vs 1.0 distinction, key order, and big integers — so existing JSON pipelines can carry Weft losslessly.
  • Hardened against hostile input (SPEC §9–10). Resource limits are enforced early on every entry point; parsing is iterative/depth-capped (no stack overflow in any of the four implementations); lone surrogates, duplicate JSON keys, huge integer literals, and prototype pollution are all rejected by design. See SECURITY.md.

Repository layout

Path What
spec/SPEC.md The normative specification (revision 1.0.1)
impl-python/ Python reference implementation
impl-typescript/ TypeScript reference implementation
impl-rust/ Rust reference implementation
impl-go/ Go reference implementation
tests/conformance/ Language-neutral conformance suite (byte-exact, 4-way)
tests/fuzz/ Differential fuzzer across all four implementations
CHANGELOG.md 1.0.1 changes
SECURITY.md Threat model and vulnerability reporting

All four implementations expose the same surface: parse, format_value (default pretty / §7.3 strict canonical), equals (SPEC §5.16), the lossless and lossy JSON mappings, and configurable resource limits.

Quick start

Python

import json
import weft
v = weft.parse('{:a 1 :b [1.5 2n]}')
print(weft.format_value(v))                       # pretty
print(weft.format_value(v, weft.FormatOptions(strict_canonical=True)))
j = weft.to_json_lossless(v)                      # → plain JSON types
v2 = weft.loads_json(json.dumps(j))               # … and back, losslessly
assert weft.equals(v, v2)

TypeScript — npm install && npm run build, then weft.parse / formatValue / loadsJson / equals.

Rust — weft::parse / format_value / loads_json_lossless / equals.

Go — weft.Parse / FormatValue / LoadsJSONLossless / Equals.

Testing

python3 tests/conformance/run.py --build   # 4 implementations, byte-exact corpus
python3 tests/fuzz/diff_fuzz.py            # differential fuzz (deterministic seed)
python3 tests/check_package.py             # package completeness + version lockstep

Each implementation also ships a self-test (impl-python/tests/selftest.py, impl-typescript/tests/selftest.js, cargo run --bin selftest, go run ./selftest) covering the regression classes fixed in 1.0.1. CI runs all of the above on every push.

The conformance corpus is generated by 4-way agreement (tests/conformance/gen_corpus.py): a case enters the corpus only when all four implementations independently produce the same result, and any disagreement blocks regeneration. See tests/conformance/README.md.

Versioning

Spec revisions and all four implementation version strings move in lockstep (enforced by tests/check_package.py). Format-visible changes only happen in a new spec revision.

License

MIT

About

An AI-first data format: one canonical byte encoding, machine-readable errors, exact decimals, lossless JSON bridge. Spec v1.0 with reference implementations in Python, TypeScript, Rust, and Go.

Topics

Resources

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages