Skip to content
Topaz6.0 · Before release
Download

Search documentation

Specification 6.0 · Not released · Tested product 5.21.3

Use arrow keys to choose a result. Press Enter to open.

Type an API name, diagnostic number, rule, or project topic.

    Diagnostics

    TPZ5533: Type is not JSON encodable

    JSON.stringify or a JSON encode path received a type outside the supported deterministic JSON shape.

    Diagnostic and cause

    Link

    Type is not JSON encodable

    Family
    topaz
    Phase
    check
    Code
    TPZ5533

    Cause and conditions

    json.stringify requires a JSON-encodable argument type. Passing a function value is rejected with TPZ5533; passing the function's integer result is accepted.

    Response

    Project the value into supported JSON data. Encode its data fields instead of passing behavior or opaque host values.

    Source evidence

    Compiler phase: check.

    Compiler explanation: JSON.stringify or a JSON encode path received a type outside the supported deterministic JSON shape.

    Message templates. The marker ⟨value⟩ stands for text computed for the reported program.

    • ⟨value⟩ is not JSON-encodable, so json.stringify cannot encode it Source

    json.stringify requires a JSON-encodable argument type. Passing a function value is rejected with TPZ5533; passing the function's integer result is accepted.

    Rulediagnostics.tpz5533.p5.rule

    Type is not JSON encodable

    json.stringify requires a JSON-encodable argument type. Passing a function value is rejected with TPZ5533; passing the function's integer result is accepted.

    Source evidence

    Response

    Link

    Project the value into supported JSON data. Encode its data fields instead of passing behavior or opaque host values.

    Reproduction and verification

    Link

    Rejected program

    Link
    example.tpzRejected programOpen in Playground
    1. import std.json
    2. function compute() -> int { 1 }
    3. let encoded = json.stringify(compute)
    Expected outputNonzero exit
    No stdout.
    $ topaz check example.tpz · target product 5.21.3
    Expected result

    Expected result

    Rejection during check. Nonzero exit.

    • TPZ5533 diagnostic-tpz5533 at example.tpz:3:15
    Source evidence

    Repaired program

    Link
    example.tpzRepaired program
    1. import std.json
    2. function compute() -> int { 1 }
    3. let encoded = json.stringify(compute())
    Expected outputexit 0
    $ topaz check example.tpz · target product 5.21.3
    Expected result

    Expected result

    Checking accepts the program. Exit code 0.

    Source evidence

    Menu

    Download