Skip to main content
Glama
json_utils.ts1.28 kB
/** * Utilities for JSON manipulation with support for special types like BigInt */ /** * Replacer function for JSON.stringify that handles BigInt * * @param key - Key of the key-value pair being processed * @param value - Value being processed * @returns The transformed value if necessary (BigInt converted to string) */ export const bigIntReplacer = (key: string, value: unknown): unknown => typeof value === 'bigint' ? value.toString() : value; /** * Serializes an object to JSON while properly handling BigInt values * * @param obj - The object to serialize * @param space - Number of spaces to use for indentation (optional) * @returns JSON string with BigInt values converted to strings */ export function safeStringify(obj: unknown, space?: number): string { return JSON.stringify(obj, bigIntReplacer, space); } /** * Attempts to parse JSON while handling errors gracefully * * @param text - The JSON string to parse * @param defaultValue - Value to return if parsing fails * @returns The parsed object or defaultValue if an error occurs */ export function safeParse<T>(text: string, defaultValue?: T): T | null { try { return JSON.parse(text) as T; } catch (error) { return defaultValue !== undefined ? defaultValue : null; } }

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/Laz1mov/mcp-inscription'

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