louise
The Louise language: compiler, runtime, std, tooling
Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.
Dernier runÉchoué#94 · main · 15 min 28 s
0Étoiles
0Forks
40Issues
ADR 0075: JSON is a package, packages/json
Status: Proposed (2026-11-03); needs engineering review (#44).
Context
- There is no JSON. std has MessagePack (
std/msgpack, ADR 0051) but nothing for JSON, so apps work around it. toki2 wroteinfra/web/flat_json, which reads one flat object of strings and whole numbers, has no escapes and no encoder. A JSON HTTP API (Starfleet API, a SpaceTraders-style game) needs both directions, on untrusted bodies. - Where it goes.
std/msgpackis in std because the runtime and the event store examples lean on it. JSON is a web format. Its API (value shape, number model, decoder style) is the kind of thing that changes in its first months, and std is versioned with the compiler. - ADR 0019's derives only consume.
@derivablefits an encoder (fn to_json(x: a) -> Value) but not a decoder, the same gap ADR 0051 records forFromMsgPack.
Decision
- A package, not std:
packages/json, depended on by a git tag likeuuidandweb. It is pure Louise overBytes, so it needs no externs and runs in both backends. Moving it into std later stays possible if it settles. Value:Null | Bool | Int | Float | String | Array(List) | Object(List<(String, Value)>).- Integers are exact (a big
Int), which JavaScript'sNumberis not. A client that needs more than 2^53 must use a big-number reader. - Objects keep their order and refuse duplicate keys. Order is what
makes
writedeterministic (tests, docs, signatures over a body). Refusing duplicates closes the "which"admin"wins" ambiguity between parsers.
- Integers are exact (a big
parseis hardened likestd/msgpack.read:- every error carries a byte offset;
- depth is capped at 512;
- escapes are checked, and lone surrogates refused;
- control characters in strings are refused;
- the RFC number grammar is checked before
float.parse, which on its own acceptsinfand.5; - a number that overflows a
Floatis refused.
writeandpretty:- Escape only what RFC 8259 requires.
- A non-finite
Floatpanics, asmsgpack.writepanics on anIntoutside int64: silently writingnullwould change the data.
@derive(ToJson)usesToMsgPack's convention (a record becomes an object, a positional constructor a{Name: [...]}object, a constructor without fields its name), so one type reads the same in both formats.Optionisnullor the value, which is what JSON APIs expect.- Decoding uses decoder combinators (
json/decode), not aFromJsontrait:field name inner nexttakes the rest of the decoder as a continuation, so a record decoder is oneuseline per field.- Errors carry the path (
Mismatch(path, expected, found),Missing(path, name), shown as$.ships.1: …), which an API can hand straight back in a 422. - A trait would need one impl per type anyway (no producer derives) and could not take parameters (a different decoder for one endpoint).
Consequences
- Apps replace their hand-written JSON (toki2's
flat_json). - When ADR 0051's producer derives land, a
@derive(FromJson)could buildjson/decodedecoders. That would be additive. - CI checks, tests and natively tests the package with the others
(
scripts/ci.sh, packages part). - Not done here:
- streaming (SAX-style) parsing;
- a JSON Pointer or path query API;
- escaping of U+2028 and U+2029 for embedding in
<script>, which is the HTML layer's job.