Lossless Encoder for Shared and Cyclic Object Graphs
Loading workflow…
Workflow Description
A self-contained n8n workflow that builds four fictional object graphs inside a Code node and encodes each into a JSON-safe {rootRef, nodes} envelope with one stable id per object or array. A second Code node decodes the envelope in memory and verifies primitive values, reference identity and cycle restoration (root.child.parent === root). Results are tagged, routed by IF, merged, and aggregated into one report separating circular edges from shared references and listing rejected types with path and reason.
How it works
- 1.Manual Trigger starts the demo; the encoder Code node builds a plain tree, a twice-referenced shared object, a reference cycle and an unsupported function value.
- 2.A WeakMap assigns one id per object/array while a DFS ancestor Set classifies repeats as circular edges or shared references.
- 3.The node table stores type plus properties as refs or primitives; unsupported types are rejected with path and reason.
- 4.The decoder allocates all nodes empty, fills them, then checks JSON.stringify, recorded primitives, reference identity and the cycle probe.
- 5.Set tags verificationStatus (includeOtherFields), IF splits valid/failed to NoOp branches, Merge appends, and a final Code node emits one aggregated report.
Use cases
- Diagnosing 'Converting circular structure to JSON' failures inside Code nodes
- Moving shared or cyclic JavaScript structures as restorable JSON
- Auditing cycles and shared references in complex debug payloads
Requirements
- n8n 2.48.7 with manualTrigger, code, set, if, merge, noOp and stickyNote nodes
- No credentials, no network, no external libraries; processing is fully local
- For real data: edit the case list inside the encoder Code node
Setup and testing in n8n
- Import the JSON and run the Run Demo node manually
- Verify the single final item: caseCount=4, nodeCount=8, circularEdgeCount=1, sharedReferenceCount=1, rejectedCount=1, roundTripValid=true
- Inspect the unsupported_type case: rejected contains root.fn with reason 'unsupported type: function'
- Add a case with a broken reference or symbol and confirm failures are reported and routed to the failed branch without execution errors
Service Value
Ready-made workflow template for automation delivery and service execution.
Apps Used
Details
How to Use
- 1.Click "Download Template"
- 2.Open your n8n dashboard
- 3.Go to Workflows > Import from File
- 4.Select downloaded file and configure credentials
Nodes Used (9)
Run Demo
Manual Trigger
Build and Encode Sample Graphs
Code
Decode and Verify Round-Trip
Code
Tag Verification Status
Set
Round-Trip Valid?
If
Verified Cases
No Op
Failed Cases
No Op
Merge Branches
Merge
Build Final Report
Code
Note Input
Sticky Note
Note Encoding
Sticky Note
Note Verification
Sticky Note
Note Routing
Sticky Note
Fresh workflows, straight to your inbox
Get newly published DROPIDEA workflows, a clear overview of what they do, and a link to explore them.
- New workflows
- Clear overviews
- Setup guides