Skip to main content
Glama
runtime-validation.md992 B
## Runtime Validation Deserialize validates the input data and throws descriptive errors: <InteractiveMacro code={`/** @derive(Deserialize) */ class User { name: string; email: string; }`} /> ```typescript // Missing required field User.fromJSON({ name: "Alice" }); // Error: User.fromJSON: missing required field "email" // Wrong type User.fromJSON("not an object"); // Error: User.fromJSON: expected an object, got string // Array instead of object User.fromJSON([1, 2, 3]); // Error: User.fromJSON: expected an object, got array ``` ## Automatic Type Conversion Deserialize automatically converts JSON types to their TypeScript equivalents: | string/number/boolean | `string`/`number`/`boolean` | Direct assignment | ISO string | `Date` | `new Date(string)` | array | `T[]` | Maps items with auto-detection | object | `Map<K, V>` | `new Map(Object.entries())` | array | `Set<T>` | `new Set(array)` | object | Nested class | Calls `fromJSON()` if available

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