How to Print a Circular Structure in a JSON-like Format
The circular structure is not in JSON, but in the object that is being converted to JSON. The circular structure come from objects that contain something which references the original object.
To convert a circular structure to JSON format can be possible with JSON.stringify. Use it with a custom replacer like in this example:
The replacer in the given example is not 100% correct which depends on your definition of "duplicate".
In this case, a value is discarded but it uses a custom replacer, and keep track of the parsed object values:
The JSON.stringify() Method
The JSON.stringify() method is used for converting a JavaScript object or value to a JSON format, optionally replacing values if a replacer function is specified or optionally including only the specified properties if a replacer array is specified.
Replacer is a function that modifies the behaviour of the stringification process, or an array of string and number objects. If the value of replacer is null or not given, all object's properties are included in the resulting JSON string.