Skip to content

Instantly share code, notes, and snippets.

@AndersDJohnson
Last active June 5, 2019 13:34
Show Gist options
  • Select an option

  • Save AndersDJohnson/4395147 to your computer and use it in GitHub Desktop.

Select an option

Save AndersDJohnson/4395147 to your computer and use it in GitHub Desktop.
JSON stringify circular replacer
JSONCircular = (circularValue = '[Circular]') ->
cache = [];
return (key, value) ->
if (typeof value is 'object' && value isnt null)
if (cache.indexOf(value) isnt -1)
return circularValue;
cache.push(value);
return value;
# use:
# JSON.stringify(object, JSONCircular())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment