New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

decycle

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

decycle

JSON decycle replaces circular references with JSON path references

latest
Source
npmnpm
Version
1.0.0
Version published
Weekly downloads
192
-41.1%
Maintainers
1
Weekly downloads
 
Created
Source

decycle

NPM

NPM version build codecov

JSON decycle replaces circular references with {"$ref": PATH}, where PATH is the JSONPath of the first occurrence.

Inspired by cycle.js.

Quick Start

import { decycle } from 'decycle';

const obj = { a: 1 };
obj.self = obj;

JSON.stringify(decycle(obj));
// '{"a":1,"self":{"$ref":"$"}}'

Install

NPM:

npm install decycle

Yarn:

yarn add decycle

CDN:

<script src="https://unpkg.com/decycle@latest/dist/index.umd.js"></script>

Usage

ES Modules:

import { decycle } from 'decycle';

CommonJS:

const { decycle } = require('decycle');

UMD:

<script src="https://unpkg.com/decycle@latest/dist/index.umd.js"></script>
<script>
  const { decycle } = window.decycle;
</script>

decycle(value, replacer?)

Returns a deep copy of object or array with circular references replaced by {"$ref": PATH}.

value

Type: unknown

The object or array to decycle.

replacer

Type: (value: unknown) => unknown

Optional replacer function called for each value. It receives a value and returns a replacement value.

Examples

Circular array:

const array = [];
array[0] = array;
JSON.stringify(decycle(array)); // '[{"$ref":"$"}]'

With replacer:

const obj = { date: new Date('2026-02-07') };
const result = decycle(obj, (value) =>
  value instanceof Date ? value.toISOString() : value,
);
// { date: '2026-02-07T00:00:00.000Z' }

Release

Release is automated with Release Please.

License

MIT

Keywords

JSON

FAQs

Package last updated on 08 Feb 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts