Skip to content

[P2] Add a bounded JSON parser and writer usable from Semaprax programs #63

Description

@wsdt

Audit: 2026-09-05, commit 2b3b1ee24da2.
Classification: Documented standard-library gap; proposed data-processing enhancement. Priority: P2.

Finding

std.data.json is explicitly missing in docs/STANDARD-LIBRARY-V1.md. The Rust compiler's use of serde_json does not expose JSON processing to a Semaprax program. The existing byte/text/encoding primitives and project library packaging are a starting point, not a complete application JSON API.

For an agent-native language this is a high-value everyday capability: model responses, configuration, structured tool results, and API payloads are JSON.

First implementation boundary

Create a versioned pure parser over an explicit borrowed byte input with fixed input, nesting, token/node, decoded-string, and output limits. Start with a bounded token/arena document whose views cannot outlive the source, or use an owned representation only after its collection/cleanup contract exists. Do not depend on an unimplemented general map.

Support the complete JSON lexical forms in the admitted slice. Specify duplicate-key policy, exact integer handling, fractional/exponent representation, UTF-8 and surrogate rules, and source-offset diagnostics. A writer should produce valid deterministic JSON and never silently round an i64/usize through an f64.

Acceptance criteria

  • Parse/serialize round-trips across objects, arrays, strings/escapes, booleans, null, signed limits, and fractional/exponent examples.
  • Invalid UTF-8, lone surrogates, invalid number grammar, excessive depth, capacity exhaustion, and duplicate keys follow the documented deterministic policy.
  • No input/output truncation is accepted as a complete document.
  • Borrowed values cannot escape their source; owned values clean up exactly once on every failure path.
  • Interpreter, native, and Wasm conformance use the same corpus, including exact numeric boundaries and Unicode.
  • Add an offline project that validates an agent-style response and writes a structured result.
  • Register the package in std/packages.json, regenerate both catalogs, and extend tests/project/standard_library.rs.

Dependencies: a token-view parser can be independent; an arbitrary owned JSON tree depends on an admitted collection and ownership slice. Keep parser data separate from executable tool authority.

Agent handoff

Recheck the working revision and existing issues first. Read AGENTS.md, the relevant completion-matrix row, and the owning versioned specifications. This proposed slice must preserve canonical source, independent replay, precise target admission, and separately granted authority. Place regressions in the existing owning harness. Execute the applicable quality gates and record what actually ran; unrun native, hosted, or device evidence must stay unpromoted.

Audit revision scope

Runtime observations in this ticket belong to commit 2b3b1ee. A final source-tree comparison against e1c5b56 was used to check for obvious superseding changes. That later snapshot was not rebuilt or exhaustively retested. Reproduce on the intended fixing revision before implementation.

Audit ID: SPX-AUDIT-20260905-15

Suggested scope: L. Dependencies: None required.

Activity

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