UNPKG

@prsna_ai/mcp-server

Version:

Model Context Protocol server for PRSNA personality profiles and communication insights

46 lines 1.43 kB
// Safe JSON stringify that handles circular references and undefined values export function safeJSONStringify(obj, space) { const seen = new WeakSet(); return JSON.stringify(obj, (key, value) => { // Handle circular references if (typeof value === 'object' && value !== null) { if (seen.has(value)) { return '[Circular Reference]'; } seen.add(value); } // Handle undefined values if (value === undefined) { return null; } // Handle functions if (typeof value === 'function') { return '[Function]'; } // Handle Date objects if (value instanceof Date) { return value.toISOString(); } return value; }, space); } // Clean object by removing undefined values and functions export function cleanObject(obj) { if (obj === null || obj === undefined) { return obj; } if (Array.isArray(obj)) { return obj.map(cleanObject).filter(item => item !== undefined); } if (typeof obj === 'object') { const cleaned = {}; for (const [key, value] of Object.entries(obj)) { if (value !== undefined && typeof value !== 'function') { cleaned[key] = cleanObject(value); } } return cleaned; } return obj; } //# sourceMappingURL=json.js.map