Unmarshal recursive JSON

Trying to parse the LSP specification vscode-languageserver-node/protocol/metaModel.json at main · microsoft/vscode-languageserver-node · GitHub using core:encoding/json.unmarshal() I ended up with this gem of a model:

Type :: struct {
    kind: string,
    name: Maybe(string),
    element: Maybe(Type),
    items: Maybe([]Type),
}

The compiler dev-2026-10:84bc3fc21 segfaults on this. This is understandable (though an error message would be better) because this struct is self-referencing and has an infinite size. Question is, how do I break the loop? The corresponding JSON might look like this, literally the first example from the spec:

{
    "kind": "or",
    "items": [
        {
            "kind": "reference",
            "name": "Definition"
        },
        {
            "kind": "array",
            "element": {
                "kind": "reference",
                "name": "DefinitionLink"
            }
        },
        {
            "kind": "base",
            "name": "null"
        }
    ]
}

I tried to replace element: Maybe(Type) with element: Maybe(^Type) but that failed to parse with Unsupported_Type_Error.

For the record, I found two solutions:

  1. Replace Maybe(Type) with ^Type and implement a custom unmarshaler for ^Type. The custom unmarshaler allocates a Type struct and then delegates to a standard unmarshaler for objects. I ended up not using this because I couldn’t come up with a convenient Type struct definition which would cover all use cases.
  2. Unmarshal any type fields into json.Value and then parse on demand into a union of well defined types that the spec supports:
    Any_Type :: union {
        Base_Type,
        Reference_Type,
        Pointer_Type, // work-around for SelectionRange which is self-referencing in the spec
        Array_Type,
        Or_Type,
        Map_Type,
        String_Literal_Type,
        Any_Object_Type,
        Invalid_Type, // convenience type to emit errors into the generated source
    }