# decircular

> Remove circular references from objects

Latest version **1.0.0** (published 2024-03-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install decircular
pnpm add decircular
yarn add decircular
bun add decircular
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2024-03-10 |
| First published | 2023-11-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | >=18 |
| Dependencies | 0 |
| Unpacked size | 4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Sindre Sorhus |
| Maintainers | sindresorhus |
| Keywords | circular, object, destroy, remove, reference, ref, copy, array, serialization, json, stringify, cyclic |

## Links

- npm: https://www.npmjs.com/package/decircular
- Repository: https://github.com/sindresorhus/decircular
- Homepage: https://github.com/sindresorhus/decircular#readme
- Issues: https://github.com/sindresorhus/decircular/issues
- Funding: https://github.com/sponsors/sindresorhus
- npm.io page: https://npm.io/package/decircular

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.0.0 (latest) — 2024-03-10
- 0.1.1 — 2023-11-17
- 0.1.0 — 2023-11-14

## README

# decircular

> Remove circular references from objects

Circular references occur in JavaScript when an object references itself or creates a loop of references involving other objects. This can lead to issues like infinite loops and errors during serialization (e.g., with `JSON.stringify`). This package replaces circular references in objects or arrays with clear path notations (e.g., `[Circular *a.1.b]`). Ideal for data serialization, debugging, and logging.

## Install

```sh
npm install decircular
```

## Usage

```js
import decircular from 'decircular';

const object = {
	a: 1,
	b: {
		c: 2
	}
};

object.b.d = object.b; // Creates a circular reference

console.log(decircular(object));
/*
{
	a: 1,
	b: {
		c: 2,
		d: '[Circular *b]'
	}
}
*/
```

## API

### decircular(object)

Returns a deep copy of the given object or array with circular references removed.

## Related

- [safe-stringify](https://github.com/sindresorhus/safe-stringify) - Serialize objects to JSON with handling for circular references

---
_Source: https://npm.io/package/decircular · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
