{"id":13594797,"url":"https://github.com/unjs/destr","last_synced_at":"2025-12-11T21:09:26.441Z","repository":{"id":42362542,"uuid":"265543640","full_name":"unjs/destr","owner":"unjs","description":"🚀 Faster, secure and convenient alternative for JSON.parse for arbitrary inputs","archived":false,"fork":false,"pushed_at":"2025-12-03T05:26:02.000Z","size":756,"stargazers_count":1349,"open_issues_count":11,"forks_count":20,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-12-05T19:36:16.506Z","etag":null,"topics":["deno","json","jsonparse","node","nodejs"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/unjs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2020-05-20T11:26:56.000Z","updated_at":"2025-12-03T16:26:57.000Z","dependencies_parsed_at":"2024-02-11T02:30:02.141Z","dependency_job_id":"103ff184-c498-45c0-aed9-2efdd636f7c2","html_url":"https://github.com/unjs/destr","commit_stats":{"total_commits":177,"total_committers":19,"mean_commits":9.31578947368421,"dds":0.576271186440678,"last_synced_commit":"0d7f9694653ac5eae145c55687b9a5aa6dad730d"},"previous_names":["nuxt-contrib/destr"],"tags_count":23,"template":false,"template_full_name":null,"purl":"pkg:github/unjs/destr","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unjs%2Fdestr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unjs%2Fdestr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unjs%2Fdestr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unjs%2Fdestr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/unjs","download_url":"https://codeload.github.com/unjs/destr/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unjs%2Fdestr/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":27665059,"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","status":"online","status_checked_at":"2025-12-11T02:00:11.302Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["deno","json","jsonparse","node","nodejs"],"created_at":"2024-08-01T16:01:39.247Z","updated_at":"2025-12-11T21:09:26.364Z","avatar_url":"https://github.com/unjs.png","language":"TypeScript","readme":"# destr\n\n[![npm version][npm-version-src]][npm-version-href]\n[![npm downloads][npm-downloads-src]][npm-downloads-href]\n[![bundle][bundle-src]][bundle-href]\n[![License][license-src]][license-href]\n\nA faster, secure and convenient alternative for [`JSON.parse`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse).\n\n## Usage\n\n### Node.js\n\nInstall dependency:\n\n```bash\n# npm\nnpm i destr\n\n# yarn\nyarn add destr\n\n# pnpm\npnpm i destr\n```\n\nImport into your Node.js project:\n\n```js\n// ESM\nimport { destr, safeDestr } from \"destr\";\n\n// CommonJS\nconst { destr, safeDestr } = require(\"destr\");\n```\n\n### Deno\n\n```js\nimport { destr, safeDestr } from \"https://deno.land/x/destr/src/index.ts\";\n\nconsole.log(destr('{ \"deno\": \"yay\" }'));\n```\n\n## Why?\n\n### ✅ Type Safe\n\n```ts\nconst obj = JSON.parse(\"{}\"); // obj type is any\n\nconst obj = destr(\"{}\"); // obj type is unknown by default\n\nconst obj = destr\u003cMyInterface\u003e(\"{}\"); // obj is well-typed\n```\n\n### ✅ Fast fallback to input if is not string\n\n```js\n// Uncaught SyntaxError: Unexpected token u in JSON at position 0\nJSON.parse();\n\n// undefined\ndestr();\n```\n\n### ✅ Fast lookup for known string values\n\n```js\n// Uncaught SyntaxError: Unexpected token T in JSON at position 0\nJSON.parse(\"TRUE\");\n\n// true\ndestr(\"TRUE\");\n```\n\n### ✅ Fallback to original value if parse fails (empty or any plain string)\n\n```js\n// Uncaught SyntaxError: Unexpected token s in JSON at position 0\nJSON.parse(\"salam\");\n\n// \"salam\"\ndestr(\"salam\");\n```\n\n**Note:** This fails in safe/strict mode with `safeDestr`.\n\n### ✅ Avoid prototype pollution\n\n```js\nconst input = '{ \"user\": { \"__proto__\": { \"isAdmin\": true } } }';\n\n// { user: { __proto__: { isAdmin: true } } }\nJSON.parse(input);\n\n// { user: {} }\ndestr(input);\n```\n\n### ✅ Strict Mode\n\nWhen using `safeDestr` it will throw an error if the input is not a valid JSON string or parsing fails. (non string values and built-ins will be still returned as-is)\n\n```js\n// Returns \"[foo\"\ndestr(\"[foo\");\n\n// Throws an error\nsafeDestr(\"[foo\");\n```\n\n## Benchmarks\n\n`destr` is faster generally for arbitrary inputs but also sometimes little bit slower than `JSON.parse` when parsing a valid JSON string mainly because of transform to avoid [prototype pollution](https://learn.snyk.io/lessons/prototype-pollution/javascript/) which can lead to serious security issues if not being sanitized. In the other words, `destr` is better when input is not always a JSON string or from untrusted source like request body.\n\nCheck [Benchmark Results](./BENCH.md) or run with `pnpm run bench:node` or `pnpm run bench:bun` yourself!\n\n## License\n\nMIT. Made with 💖\n\n\u003c!-- Badges --\u003e\n\n[npm-version-src]: https://img.shields.io/npm/v/destr?style=flat\u0026colorA=18181B\u0026colorB=F0DB4F\n[npm-version-href]: https://npmjs.com/package/destr\n[npm-downloads-src]: https://img.shields.io/npm/dm/destr?style=flat\u0026colorA=18181B\u0026colorB=F0DB4F\n[npm-downloads-href]: https://npmjs.com/package/destr\n[bundle-src]: https://img.shields.io/bundlephobia/minzip/destr?style=flat\u0026colorA=18181B\u0026colorB=F0DB4F\n[bundle-href]: https://bundlephobia.com/result?p=destr\n[license-src]: https://img.shields.io/github/license/unjs/destr.svg?style=flat\u0026colorA=18181B\u0026colorB=F0DB4F\n[license-href]: https://github.com/unjs/destr/blob/main/LICENSE\n","funding_links":[],"categories":["TypeScript","Uncategorized"],"sub_categories":["Uncategorized"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funjs%2Fdestr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Funjs%2Fdestr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funjs%2Fdestr/lists"}