WebAssembly / WebAssembly/component-model

How to define the json object

Open
#335 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
WebAssembly
Stars
1.4k
Forks
130
Avg merge
2d 1h
Merged PRs (30d)
15

Description

I want to define a json structure to provide serialization and deserialization capabilities, but I encountered two problems.

  1. No mapping of dictionary type
  2. Unable to define recursive types (direct or indirect)

package endec: json@0.1.0;

world imports {
    export types;
}

interface types {
    /// The json value context
    record json {
        /// The root value
        root: value
    }
    /// A json value
    variant value {
        %null,
        %bool(bool),
        %decimal(f64),
        %string(string),
        %array(array),
        %object(object)
    }
    /// A json array
    record array {
        %list: list<value>,
    }
    /// A json object
    record object {
        %dict: list<tuple<string, value>>,
    }
}

Such a definition will report an error:

called `Result::unwrap()` on an `Err` value: failed to parse package: C:\Users\CLionProjects\serde-wasi\projects\serde-json\wit

Caused by:
    type `value` depends on itself
         --> C:\Users\CLionProjects\serde-wasi\projects\serde-json\wit\world.wit:11:15
          |
       11 |         root: value
          |               ^----

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the WIT example in the issue and the recursive-type diagnostic at world.wit:11. Review the component model's type rules for recursive values and dictionary-like mappings, then determine whether the requested JSON structure is supported or requires a design change; done means a documented resolution for both reported limitations.

Written by the indexing model from the issue text.

Assessment

Tech stack
wasm
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.