Skip to content

refactor(js)!: redesign JSON serialization and parsing around gleam_json (#13) - #26

Merged
GG-O-BP merged 1 commit into
mainfrom
refactor/gleam-json-issue-13
Sep 7, 2026
Merged

refactor(js)!: redesign JSON serialization and parsing around gleam_json (#13)#26
GG-O-BP merged 1 commit into
mainfrom
refactor/gleam-json-issue-13

Conversation

@GG-O-BP

@GG-O-BP GG-O-BP commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator

Closes #13.

Summary

Replaces the handwritten JSON FFI in glendix/js/json with gleam_json, and
redesigns the parsing boundary to be type-directed.

  • stringify(value:) keeps its public signature and now delegates to
    gleam/json.to_string (source-compatible, compact output).
  • parse now takes an explicit decode.Decoder(value) and returns the decoded
    value, delegating to gleam/json.parse(from:, using:).
  • JsonError distinguishes deterministic syntax failures
    (InvalidSyntax(JsonSyntaxError)) from decoder/type failures
    (DecoderMismatch(List(decode.DecodeError))), mapped in pure Gleam without
    JavaScript-engine-specific exception text.
  • Removes src/glendix/js/json_ffi.mjs and its externals (stringify_raw,
    parse_raw, raw_json_error_message) plus type RawJsonError.

Public API / compatibility

This is a breaking change to parse on the in-development 6.0.0 line. The old
untyped parse(from:) -> Result(json.Json, JsonError) is replaced by a
decoder-based API; migration examples are documented in README.md,
README.ko.md, and README.ja.md. glendix -> mendraw keeps its declared Hex
source.

Tests

test/glendix/js/json_test.gleam covers serialization and typed parsing for
null, scalars, escaped strings, arrays, objects, malformed input
(UnexpectedEndOfInput, UnexpectedByte), decoder mismatch, and a nested
decoder-error path. The obsolete untyped round-trip test in
test/glendix_test.gleam was removed.

Validation

  • gleam format --check, gleam check, gleam build --warnings-as-errors,
    gleam docs build: passed (glendix worktree).
  • gleam test --runtime bun: 60 passed, no failures.
  • Shared mechanical style checker: passed.
  • dependency-mode.sh check-commit glendix: valid dependency sources.
  • FFI-contract/boundary review: only removals; no new or dangling externals.

Family Lustre/Mendix browser E2E was not executed in this environment, so no
Mendix/Lustre compatibility claim is made beyond the unit/contract suite. This
module has no in-family consumers.

Replace the handwritten JSON FFI in glendix/js/json with gleam_json.

- stringify now delegates to gleam/json.to_string (source-compatible).
- parse now takes an explicit decode.Decoder and returns the decoded
  value, delegating to gleam/json.parse.
- JsonError distinguishes deterministic syntax failures (InvalidSyntax
  with JsonSyntaxError) from decoder/type failures (DecoderMismatch),
  mapped in pure Gleam without JavaScript engine-specific text.
- Remove src/glendix/js/json_ffi.mjs and its externals.
- Cover null, scalars, escaped strings, arrays, objects, malformed
  input, unexpected byte, and decoder mismatch (incl. nested path).
- Document the migration in README.md/.ko/.ja.

Closes #13
@GG-O-BP
GG-O-BP merged commit 9262707 into main Sep 7, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ffi] Replace JSON serialization and redesign parsing around gleam_json

1 participant