Skip to main content
Glama
enum-support.md707 B
## Enum Support Deserialize also works with enums. The `fromJSON` function validates that the input matches one of the enum values: <MacroExample before={data.examples.enum.before} after={data.examples.enum.after} /> ```typescript const status = Status.fromJSON("active"); console.log(status); // Status.Active // Invalid values throw an error try { Status.fromJSON("invalid"); } catch (e) { console.log(e.message); // "Invalid Status value: invalid" } ``` Works with numeric enums too: <InteractiveMacro code={`/** @derive(Deserialize) */ enum Priority { Low = 1, Medium = 2, High = 3, }`} /> ```typescript const priority = Priority.fromJSON(3); console.log(priority); // Priority.High ```

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/macroforge-ts/mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server