Skip to content

feat(json): bounded JSON values and encoding without public Serde contracts #211

Closed

Description

@zackees

Context

FastLED migration FastLED/cli#242 at73c2a33 still directly depends on serde/serde_json. Ten source modules use JSON: source receipts, dynamic-cache metadata, editor snapshots, project configuration, toolchain state, clangd settings, debug symbols, build asset manifests, DWARF smoke requests and server replies. Calls include typed records and mutable unknown-field-preserving objects. The kernel has private JSON uses, but no general owned JSON document surface for these clients.

Proposal

Add a feature-gated json module with facade-owned values, parse/encode errors, and compact/pretty output selection. Support null, booleans, UTF-8 strings, signed64/unsigned64/finite floating numbers, arrays and ordered objects. Parsing and encoding enforce documented byte/node/depth limits. Backend Serde/JSON crates remain private: no public Serialize/Deserialize bounds, derive reexports, Value aliases or generic backend convenience escape hatch.

Apps retain field names, required/optional/default semantics, enum spellings, cache versions, record validation, unknown-field preservation, trailing-newline policy and HTTP status behavior. App schema adapters should replace their derives gradually, then remove both direct Serde dependencies with boundary enforcement. Do not replace JSON with a new wire format.

Acceptance criteria

  • RED→GREEN upstream contract tests before implementation, then app dependency bans and schema-parity tests before adoption.
  • Preserve i64/u64 extrema, finite float semantics, Unicode/escaping, ordered object output, array order, compact/two-space pretty encoding, and explicit duplicate-key policy. Reject malformed/trailing/invalid UTF-8 input and nonfinite output without source-echoing errors or partial output.
  • Source/output byte bounds, decoded traversal node/depth bounds, safe bounded encoding even for values constructed by callers; document preparse versus postparse limitations honestly.
  • Private exact pins; optional API absent by default. Do not falsely claim whole-graph serde_json absence when existing kernel facilities already require it.
  • Move generic parser/encoder tests upstream, keep FastLED receipt/manifest/editor/HTTP schema and business validation tests local. Both owned and dynamic-object callers must migrate; no permanent Serde trait forwarding.
  • Full relevant tests, Clippy, review, platform checks, actual WASM compile when adopting compiler-side callers, plus HTTP/editor regression coverage. No JSPI/default-toolchain change or unmeasured speedup claim.
  • Linked PRs and usable exact published dependency without a local path patch for final release acceptance.

Decisions

  • PriorityP2: removes the last serialization implementation boundary used throughout the app.
  • Start with8MiB source/output,262144values and depth64 (root0); choose explicit errors on exceeding bounds. These are new bounded contracts, not claims that arbitrary historical input remains accepted.
  • Keep JSON separate from TOML values because null/unsigned numbers and output semantics differ; avoid a speculative generalized serialization framework.
  • Preserve current serde_json object duplicate handling (last key wins), and document it. Product schemas can impose stricter validation separately if explicitly required.
  • Use the current upstream exact JSON backend version initially; schema identity stays with FastLED.

Activity

  1. zackees commented on Sep 13, 2026

    @zackees
    CollaboratorAuthor

    Typed-record adoption exposed a concrete duplicate-key fidelity gap. New passing FastLED source-receipt baseline tests verify: omitted/null resolved_commit is None and omitted on write; u64::MAX remains exact; wrong/missing field types reject; duplicate known fields (including null then string for an optional field) reject; duplicate unknown fields are ignored. Current json::parse builds a last-key-wins BTreeMap and irreversibly loses the information needed for the app to distinguish those cases. A global reject-all-duplicates parser would also change existing behavior. Before migrating typed records, add a bounded owned duplicate-aware document/member inspection surface (including nested objects for other record schemas), retaining current parse last-key-wins behavior for dynamic-object clients. Field recognition and whether a duplicate is an error must remain application policy. Do not add public Serde bounds or an app-local JSON scanner. Refs FastLED/cli#242. Baseline tests currently pass locally; receipt production parsing is intentionally unchanged until the kernel can express this policy.

  2. zackees commented on Sep 16, 2026

    @zackees
    CollaboratorAuthor

    Complete and adopted on both sides; closing with the evidence rather than leaving it open.

    kernal-api — gated behind json, implemented in src/json.rs. with tests/json_documents.rs as its contract tests, and documented in docs/json.md. It landed with #220's application-foundations rebase.

    FastLED — adopted through the pinned release tag: crates/fastled-cli/src/dwarf_smoke.rs: use kernal_api::json::{self, Layout, Value};

    🤖 Generated with Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions