@mcp-apps/api-tools-mcp-server
Version:
MCP server for interacting with APIs and web services
30 lines • 950 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getCircularReplacer = getCircularReplacer;
exports.safeStringify = safeStringify;
/**
* Creates a replacer function for JSON.stringify that handles circular references
* by replacing them with "[Circular Reference]"
*/
function getCircularReplacer() {
const seen = new WeakSet();
return (key, value) => {
if (typeof value === 'object' && value !== null) {
if (seen.has(value)) {
return '[Circular Reference]';
}
seen.add(value);
}
return value;
};
}
/**
* Stringify an object, handling circular references
* @param obj Object to stringify
* @param space Number of spaces for indentation (default: 2)
* @returns JSON string
*/
function safeStringify(obj, space = 2) {
return JSON.stringify(obj, getCircularReplacer(), space);
}
//# sourceMappingURL=json-utils.js.map