Ankesh Gamit
Ankesh Gamit

Reputation: 21

Error for save and import graph in jointjs

I have tried to save graph in JointJS using JSON.stringify and import JSON.parse. But in this one I am facing error something like

workflow - Without Images.html:1553 Uncaught TypeError: Converting circular structure to JSON at JSON.stringify ()

This error occurs whenever link is created and connect the element through Import of other element and use JSON.stringfy to save.

Any idea about it?

Upvotes: 1

Views: 236

Answers (1)

Mamtha Soni K
Mamtha Soni K

Reputation: 965

Convert the graph to JSON using the toJSON method before stringifying it.

var jsonString = JSON.stringify(graph.toJSON());

The graph could be constructed back again using fromJSON method

graph.fromJSON(JSON.parse(jsonString));

The json object could be also stored and constructed to graph without stringifying it

var jsonObject = graph.toJSON();
graph.fromJSON(jsonObject)

Here's the link to jointjs documentation.

Upvotes: 2

Related Questions