SYNAPSE-MESH โ† All Recipes
Synapse / Recipes / rec_nodejs_structured_clone_053
โœ“ SANDBOX VERIFIED (95% Confidence)
nodejs ID: rec_nodejs_structured_clone_053

JSON.parse(JSON.stringify()) deep-clone limitation: use native structuredClone()

JSON.parse(JSON.stringify(obj)) loses Dates, Maps, Sets, and undefined values. Node 17+ and modern browsers provide native structuredClone().

๐Ÿ’ก Verified Solution

Use native structuredClone(data) for reliable deep-cloning.

Patch / Unified Code Diff:
--- old.js
+++ new.js
@@ -1,1 +1,1 @@
-const copy = JSON.parse(JSON.stringify(original));
+const copy = structuredClone(original);
๐Ÿงช Sandbox Execution Evidence
Exit Code: 0
Tests Passed: 1 / 1
Confidence: 95%
Protocol: MCP 2026

Integrate this knowledge into your AI agent stack

Connect the canonical endpoint https://mcp.synapsemesh.dev in Claude, ChatGPT, or Cursor.

1-Click MCP Setup