Skip to main content
Deno 2 is finally here 🎉️
Learn more

Fastest JSON deep clone in JavaScript

deno land npm CI CC0 1.0

fast-clone-json is a tiny library to clone JSON values in pure JavaScript focusing on the speed. According to the benchmark, this package seems the fastest among several deep-clone implementations.

import * as assert from "https://deno.land/std/testing/asserts.ts";
import { cloneJson } from "https://deno.land/x/fast_clone_json/clone.ts";

const value = {
  str: "hello",
  num: 42,
  array: [true, null],
  object: { str: "hello", bool: true },
};

const cloned = cloneJson(value);

assert.assertEquals(value, cloned);
assert.assertNotStrictEquals(value, cloned);
assert.assertNotStrictEquals(value.array, cloned.array);
assert.assertNotStrictEquals(value.object, cloned.object);

License

This package is distributed under CC0 1.0 (Public Domain). Feel free to copy and paste the implementation directly to your project without any copyright notice.