# prefer-structured-clone

Rule `unicorn/prefer-structured-clone`. Prefer using `structuredClone` to create a deep clone.

- Source: unicorn
- Technologies: JavaScript
- Kind: style
- Needs type information: no
- Autofix: yes, in at least one linter
- Reach: 12M weekly downloads of presets that enable it
- Trend: +40.1% last quarter
- Rank: #811 by reach, #1007 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `unicorn/prefer-structured-clone` | no | suggestion | package `eslint-plugin-unicorn` | [docs](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/v80.0.0/docs/rules/prefer-structured-clone.md) |
| Oxlint | `unicorn/prefer-structured-clone` | no | safe | plugin `unicorn`, category style | [docs](https://oxc.rs/docs/guide/usage/linter/rules/unicorn/prefer-structured-clone.html) |

## Code examples

### Incorrect: the rule reports this

```js
const clone = JSON.parse(JSON.stringify(foo));
```

```js
const clone = _.cloneDeep(foo);
```

### Correct: the rule accepts this

```js
const clone = structuredClone(foo);
```

Examples from the ESLint documentation.

## Enable it

### ESLint: `eslint.config.js`

```js
import unicorn from "eslint-plugin-unicorn";

export default [
  {
    plugins: { unicorn },
    rules: {
      "unicorn/prefer-structured-clone": "error",
    },
  },
];
```

### Oxlint: `.oxlintrc.json`

```json
{
  "rules": {
    "unicorn/prefer-structured-clone": "error"
  }
}
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [Unicorn recommended](https://lintradar.dev/presets/unicorn-recommended.md) | ESLint | `eslint-plugin-unicorn` | 340 | 9.5M | +30.3% |
| [Unicorn unopinionated](https://lintradar.dev/presets/unicorn-unopinionated.md) | ESLint | `eslint-plugin-unicorn` | 236 | 9.5M | +30.3% |
| [Ultracite for Oxlint](https://lintradar.dev/presets/ultracite-oxlint.md) | Oxlint | `ultracite` | 475 | 2.1M | +151.7% |
| [XO](https://lintradar.dev/presets/xo.md) | ESLint | `eslint-config-xo` | 618 | 413K | −5.0% |

## Related rules

- [unicorn/prefer-string-replace-all](https://lintradar.dev/rules/unicorn/prefer-string-replace-all.md): Prefer `String#replaceAll()` over regex searches with the global flag and `String#split().join()`.
- [unicorn/prefer-ternary](https://lintradar.dev/rules/unicorn/prefer-ternary.md): Prefer ternary expressions over simple `if` statements.
- [unicorn/prefer-single-call](https://lintradar.dev/rules/unicorn/prefer-single-call.md): Enforce combining multiple `Array#{push,unshift}()`, `Element#classList.{add,remove}()`, and `importScripts()` into one call.
- [unicorn/relative-url-style](https://lintradar.dev/rules/unicorn/relative-url-style.md): Enforce consistent relative URL style.
- [unicorn/prefer-set-has](https://lintradar.dev/rules/unicorn/prefer-set-has.md): Prefer `Set#has()` over `Array#includes()` when checking for existence or non-existence.
- [unicorn/require-array-join-separator](https://lintradar.dev/rules/unicorn/require-array-join-separator.md): Enforce using the separator argument with `Array#join()`.

---

Web page: https://lintradar.dev/rules/unicorn/prefer-structured-clone. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
