decycle
    Preparing search index...

    Function decycle

    • Makes a deep copy of an object or array, assuring that there is at most one instance of each object or array in the resulting structure. The duplicate references (which might be forming cycles) are replaced with an object of the form {"$ref": PATH} where the PATH is a JSONPath string that locates the first occurance.

      Parameters

      • value: unknown

        The object or array to decycle.

      • Optionalreplacer: ReplacerFunction

        Optional replacer function called for each value.

      Returns unknown

      • A deep copy of the object with circular references replaced by $ref objects.
      var a = [];
      a[0] = a;
      JSON.stringify(decycle(a)); // '[{"$ref":"$"}]'

      If a replacer function is provided, then it will be called for each value. A replacer function receives a value and returns a replacement value.

      JSONPath is used to locate the unique object. $ indicates the top level of the object or array. [NUMBER] or [STRING] indicates a child element or property.