Skip to content

codec: Decoded replaces the JSON value type - #281

Merged
vito merged 6 commits into
decoded-typefrom
decoded-replaces-json
Nov 9, 2026
Merged

vito merged 6 commits into
decoded-typefrom
decoded-replaces-json

Conversation

@vito

@vito vito commented Nov 9, 2026 •

Copy link
Copy Markdown
Owner

Removes the untyped JSON value type that #257 added (merged after v2.3.0, so not yet released). Data of unknown shape is now Decoded, a type you can name. With this PR, JSON, YAML and TOML are all just codec namespaces, and no format has special cases in the type checker, materialization, equality, List.join, the encoder or ScalarValue.

What changes

  • No JSON value type (codec: replace the JSON value type with Decoded).
    • Removed:
      • isJSONScalar, isJSONValue and isJSONNullValue, and every special case they guarded:
        • the compile-time check of JSON literals;
        • JSON null widening;
        • String→JSON validation and compaction;
        • "any data → JSON text" in materializeDecoded;
        • JSON data equality;
        • the JSON branch of List.join;
        • the encoder's raw-message embedding.
      • ScalarValue.jsonKey and JSONType.
    • materialize.go loses about 180 lines.
    • JSON is a plain namespace like YAML/TOML (and Random), and jsonCodec is Codec{JSONModule}. There is no namespace-specific check or error: written as a type, JSON! names the namespace's own type, as Random! does.
    • Migration: :: JSON! becomes :: Decoded!, and "text" :: JSON! becomes JSON.decode("text") :: Decoded!.
    • A schema's scalar JSON (Dagger.JSON) is unchanged: it is a plain schema scalar.
  • Directive argument types resolve where they are declared (directives: resolve arg types where declared).
    • Before, an imported schema's or Dang module's directive @meta(level: Level) typed level in the applying file's scope. There, Level may be the file's own type, or a builtin such as the JSON namespace.
    • Directives now remember their declaring scope and resolve argument types there.
  • Docs.
    • The lit page's "Data of unknown shape {#json-values}" section is gone. Its cases are covered by the "Keeping data undecoded" {#decoded-values} section, and every reference now points there.
    • The skill references describe Decoded instead of the JSON value.
    • The JSON.decode doc no longer claims to take a JSON value.
  • Tests.
    • analysis lists JSON's members as it lists Random's (TestDocOfStatics), now that the name JSON is only the namespace.
    • test_json_value.dang is deleted.
    • Its cases that no Decoded test covered are ported to test_decoded_encode.dang:
      • encode options inside the data;
      • strict decoding around a Decoded field;
      • TOML;
      • toString/join.
    • The JSON cast error tests (json_cast_invalid, json_literal_not_json) go with the feature.

Maintainer decisions

  • D1: Decoded (first-class, opaque) replaces codec: make JSON an untyped JSON value #257's JSON value type. That type is unreleased, so this change needs no deprecation path.
  • D8 follow-through: splitting the JSON namespace from the JSON type left isJSONScalar as it was on main. This PR removes the type, so isJSONScalar and every identity check that went with it are gone.
  • Q-41 B: builtin namespaces are automatically provided imports with no downstream special-casing, so this PR adds no namespace check or error.
  • Release note (migration): in v2.3.0, x: JSON! named a builtin JSON scalar. It now names the JSON namespace, like Random!, so such code fails with a generic type error (cannot use String! as JSON!). Write Decoded! for data of any shape (JSON.decode(text) :: Decoded!), or Dagger.JSON! (a schema's own scalar) for the server's JSON values.

Testing

dang fmt, goldens reviewed, and every check (**) passes.

  • New Go tests: TestRunDirImportedDirectiveArgsUseSchemaTypes and TestRunDirImportedNativeDirectiveArgsUseModuleTypes (both fail without the directive fix).
  • New language test: test_decoded_encode.
  • Self-reviewed with the multi-agent reviewer; its findings are addressed.

#257 (unreleased) made the type named JSON an untyped value held as JSON
text, which put format special cases in the checker, materialization,
equality, enum literal checks, List.join, the encoder and ScalarValue
(isJSONScalar, jsonKey). Decoded now names data of any shape without
belonging to a format, so the JSON value type goes: JSON is a plain
namespace like YAML and TOML (and Random). `:: JSON` code moves to
`:: Decoded!` (or a schema's own scalar, `Dagger.JSON`), and String-to-JSON
casts to `JSON.decode(s)`.

The lit docs drop the "Data of unknown shape" section (its cases are
covered by #decoded-values) and point its references there.
@vito
vito added this pull request to stack #282 November 9, 2026 15:15
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Deploying dang with  Cloudflare Pages  Cloudflare Pages

Latest commit: 74ead6d
Status: ✅  Deploy successful!
Preview URL: https://7937b984.dang-3kk.pages.dev
Branch Preview URL: https://decoded-replaces-json.dang-3kk.pages.dev

View logs

vito added 2 commits November 9, 2026 15:42
A directive's argument types were resolved in the applying file's scope, so
an imported schema's or Dang module's `@meta(level: Level)` read `Level` as
whatever that file binds to the name (its own enum, or a builtin such as the
JSON namespace) rather than the declaring module's type. Directives now
remember the scope they are declared in (a schema's, or the one a Dang
declaration is hoisted into) and resolve argument types there.

Signed-off-by: Alex Suraci <[email protected]>
Ports the cases of the removed JSON value tests that no Decoded test
covered: JSON.encode options inside Decoded data, strict decoding around a
Decoded field, TOML into Decoded, and toString/join of collections holding
it.

Signed-off-by: Alex Suraci <[email protected]>
@vito
vito force-pushed the decoded-replaces-json branch from 6e59af4 to d3bb2eb Compare November 9, 2026 15:43
@vito vito changed the title codec: replace the JSON value type with Decoded codec: replace the JSON value type with Decoded (no namespace checks) Nov 9, 2026
@vito vito changed the title codec: replace the JSON value type with Decoded (no namespace checks) codec: Decoded replaces the JSON value type Nov 9, 2026
The codec pages and skill references explained Decoded by the JSON value
type it replaces ("No JSON value type", "hold functions, not data", "Dang
has no JSON value type of its own") and carried a migration note. Describe
the current types instead: Decoded holds data of any shape, JSON is the
codec namespace, and a schema's scalar JSON is an ordinary schema scalar.
Drop JSON from the examples of custom GraphQL scalars, since unqualified it
names the namespace.

Signed-off-by: Alex Suraci <[email protected]>
@vito
vito force-pushed the decoded-replaces-json branch from d3bb2eb to 2cf0dfa Compare November 9, 2026 21:47
The strict-decoding section said a Decoded value takes any key, without
the catch the decoded-values section states: a later cast of data from a
strict decode is strict too.

Signed-off-by: Alex Suraci <[email protected]>
@vito
vito force-pushed the decoded-replaces-json branch from f2dc2d9 to 80d9679 Compare November 9, 2026 22:13
With the JSON value type gone, the name JSON names the codec namespace
in both namespaces, so its members list like Random's and the lookup of
a name's separate value namespace has nothing left to find.

Signed-off-by: Alex Suraci <[email protected]>
@vito
vito force-pushed the decoded-replaces-json branch 2 times, most recently from 447f59c to 74ead6d Compare November 9, 2026 22:46
@vito
vito merged commit 7fdc20b into main Nov 9, 2026
9 checks passed
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.

1 participant