Skip to main content
Glama
json-logic.ts1.16 kB
/** * JSON Logic expression evaluation */ // @ts-ignore - json-logic-js doesn't have type definitions import jsonLogic from "json-logic-js"; import { logger } from "../logger.js"; /** * Evaluate a JSON Logic rule with the given context data * @param rule - JSON Logic rule (can be any valid JSON Logic structure) * @param context - Context data object to evaluate the rule against * @returns Boolean result of the rule evaluation */ export function evaluateJsonLogic( rule: unknown, context: Record<string, unknown> ): boolean { try { logger.debug(`Evaluating JSON Logic rule: ${JSON.stringify(rule)}`); logger.debug(`Context keys: ${Object.keys(context).join(", ")}`); const result = jsonLogic.apply(rule, context); logger.debug(`JSON Logic result: ${result}`); // JSON Logic returns a boolean, but we'll ensure it's a boolean return Boolean(result); } catch (error) { logger.error(`JSON Logic evaluation error: ${error instanceof Error ? error.message : String(error)}`); throw new Error( `Failed to evaluate JSON Logic rule: ${error instanceof Error ? error.message : String(error)}` ); } }

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/TeamSparkAI/mcpGraph'

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