Skip to content

Instantly share code, notes, and snippets.

@dturton
Created October 9, 2022 17:42
Show Gist options
  • Save dturton/de57ac157e410f69b343bdd095cfa21b to your computer and use it in GitHub Desktop.
Save dturton/de57ac157e410f69b343bdd095cfa21b to your computer and use it in GitHub Desktop.
JSON.stringify() -- Converting circular structure to JSON - workaround
const getCircularReplacer = () => {
const seen = new WeakSet();
return (_key: any, value: object) => {
if (typeof value === "object" && value !== null) {
if (seen.has(value)) {
return;
}
seen.add(value);
}
return value;
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment