{"id":18013415,"url":"https://github.com/milly/fast-clone-json","last_synced_at":"2025-06-20T15:11:55.343Z","repository":{"id":151838639,"uuid":"624880544","full_name":"Milly/fast-clone-json","owner":"Milly","description":"Clone plain JSON value fast","archived":false,"fork":false,"pushed_at":"2023-04-07T17:47:05.000Z","size":372,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-03T14:44:19.450Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"cc0-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Milly.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-04-07T13:43:35.000Z","updated_at":"2023-05-03T06:10:16.000Z","dependencies_parsed_at":null,"dependency_job_id":"d9d8d824-64a1-4d24-b015-b28b5b583007","html_url":"https://github.com/Milly/fast-clone-json","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Milly%2Ffast-clone-json","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Milly%2Ffast-clone-json/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Milly%2Ffast-clone-json/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Milly%2Ffast-clone-json/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Milly","download_url":"https://codeload.github.com/Milly/fast-clone-json/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247190628,"owners_count":20898793,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-30T03:21:29.446Z","updated_at":"2025-04-04T14:22:15.354Z","avatar_url":"https://github.com/Milly.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Fastest JSON deep clone in JavaScript\n\n[![deno land][deno-badge]][deno] [![npm][npm-badge]][npm] [![CI][ci-badge]][ci]\n[![CC0 1.0][license-badge]][license]\n\nThis project is based on\n[fast-json-clone](https://www.npmjs.com/package/fast-json-clone).\n\n[fast-clone-json][npm] is a tiny library to clone [JSON][json] values in pure\nJavaScript focusing on the speed. According to [the benchmark](./bench), this\npackage seems the fastest among several deep-clone implementations.\n\n```javascript\nimport * as assert from \"assert\";\nimport { cloneJson } from \"fast-clone-json\";\n\nconst value = {\n  str: \"hello\",\n  num: 42,\n  array: [true, null],\n  object: { str: \"hello\", bool: true },\n};\n\nconst cloned = cloneJson(value);\n\nassert.deepStrictEqual(value, cloned);\nassert.notStrictEqual(value, cloned);\nassert.notStrictEqual(value.array, cloned.array);\nassert.notStrictEqual(value.object, cloned.object);\n```\n\n## Installation\n\nThis package is licensed with CC0-1.0. Directly copy\n[src/clone.ts](./src/clone.ts) to your project.\n\nOr install via [npm](https://npmjs.com/) package manager.\n\n```sh\nnpm install --save fast-clone-json\n```\n\n## API\n\nThis package exports `cloneJson()` and `cloneJsonObject()` functions.\n\n```javascript\ncloneJson(x: JsonValue): JsonValue;\n```\n\nThis function clones the given JSON value and returns it. There are some\ninvariants for the parameter:\n\n- The parameter must not contain circles as JSON does not allow it. This\n  function will cause infinite loop for such values by design.\n- The parameter must contain JSON values only. Other values like `Date`,\n  `Regexp`, `Map`, `Set`, `Buffer`, ... are not allowed.\n\n```javascript\ncloneJsonObject(x: JsonObject): JsonObject;\n```\n\nThis function clones the given JSON object and returns it. There are additional\ninvariants for the parameter:\n\n- All invariants of `cloneJson()`.\n- Directly specified parameters must be arrays or objects. Primitive values such\n  as `string` cannot be specified.\n\n## Benchmark\n\nHere is the benchmark result with large (1.2MB) JSON value. This package is the\nfastest among the implementations. Please see [the benchmark directory](./bench)\nfor more details and other results.\n\n![Performance large](https://raw.githubusercontent.com/wiki/Milly/fast-clone-json/bench/large.png)\n\n```\nNative structuredClone             x 104 ops/sec ±0.40% (76 runs sampled)\nstructuredClone polyfill           x 105 ops/sec ±0.59% (77 runs sampled)\nJSON serialize/deserialize         x 98.93 ops/sec ±0.69% (72 runs sampled)\nNaive deep clone                   x 208 ops/sec ±0.18% (88 runs sampled)\nlodash.clonedeep                   x 123 ops/sec ±2.42% (80 runs sampled)\nclone-deep                         x 194 ops/sec ±0.38% (89 runs sampled)\nrfdc (default)                     x 481 ops/sec ±0.19% (93 runs sampled)\nrfdc (proto)                       x 551 ops/sec ±0.26% (92 runs sampled)\nfastest-json-copy                  x 561 ops/sec ±0.15% (94 runs sampled)\nfast-json-clone                    x 584 ops/sec ±0.15% (95 runs sampled)\nfast-clone-json (cloneJson)        x 591 ops/sec ±0.24% (95 runs sampled)\nfast-clone-json (cloneJsonObject)  x 592 ops/sec ±0.24% (93 runs sampled)\n\nFastest is fast-clone-json (cloneJsonObject),fast-clone-json (cloneJson)\n```\n\n## FAQ\n\n### Why is this package the fastest?\n\nSince this package is optimized for removing non-inline function calls in the\nhot loop as much as possible. [rfdc][rfdc] is implemented with the same\nstrategy.\n\n### Then why is this package faster than rfdc?\n\nSince this package provides less functionalities. rfdc provides support for some\nnon-JSON types (`Date`, `Regexp`, ...). It increases the number of branches in\nthe hot loop so it causes trade-off in performance.\n\n### Why are my benchmark results different?\n\nYou are right. Improvements in this package are minor. In some cases it may be\nslower. (eg, differences in CPUs and Javascript engines.)\n\n## License\n\nThis package is distributed under [CC0 1.0][license] (Public Domain). Feel free\nto copy and paste the implementation directly to your project without any\ncopyright notice.\n\n[ci]: https://github.com/Milly/fast-clone-json/actions/workflows/ci.yml\n[ci-badge]: https://github.com/Milly/fast-clone-json/actions/workflows/ci.yml/badge.svg\n[deno]: https://deno.land/x/fast_clone_json\n[deno-badge]: https://img.shields.io/badge/deno.land-x%2Ffast__clone__json-lightgrey?logo=deno\n[npm]: https://www.npmjs.com/package/fast-clone-json\n[npm-badge]: https://badge.fury.io/js/fast-clone-json.svg\n[license]: https://github.com/Milly/fast-clone-json/blob/master/LICENSE\n[license-badge]: https://img.shields.io/github/license/Milly/fast-clone-json\n[json]: https://json.org/\n[rfdc]: https://github.com/davidmarkclements/rfdc\n[benchmark]: https://github.com/Milly/fast-clone-json/tree/master/bench#readme\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmilly%2Ffast-clone-json","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmilly%2Ffast-clone-json","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmilly%2Ffast-clone-json/lists"}