Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
D

destr

> 编程语言
Open source

Faster, secure and convenient alternative for JSON.parse for arbitrary inputs

1.4K stars0 likes1 views
WebsiteGitHub

About

Faster, secure and convenient alternative for JSON.parse for arbitrary inputs

destr

npm version npm downloads bundle License

A faster, secure and convenient alternative for JSON.parse.

Usage

Node.js

Install dependency:

bash
# npm
npm i destr

# yarn
yarn add destr

# pnpm
pnpm i destr

Import into your Node.js project:

javascript
// ESM
import { destr, safeDestr } from "destr";

// CommonJS
const { destr, safeDestr } = require("destr");

Deno

javascript
import { destr, safeDestr } from "https://deno.land/x/destr/src/index.ts";

console.log(destr('{ "deno": "yay" }'));

Why?

✅ Type Safe

typescript
const obj = JSON.parse("{}"); // obj type is any

const obj = destr("{}"); // obj type is unknown by default

const obj = destr<MyInterface>("{}"); // obj is well-typed

✅ Fast fallback to input if is not string

javascript
// Uncaught SyntaxError: Unexpected token u in JSON at position 0
JSON.parse();

// undefined
destr();

✅ Fast lookup for known string values

javascript
// Uncaught SyntaxError: Unexpected token T in JSON at position 0
JSON.parse("TRUE");

// true
destr("TRUE");

✅ Fallback to original value if parse fails (empty or any plain string)

javascript
// Uncaught SyntaxError: Unexpected token s in JSON at position 0
JSON.parse("salam");

// "salam"
destr("salam");

Note: This fails in safe/strict mode with safeDestr.

✅ Avoid prototype pollution

javascript
const input = '{ "user": { "__proto__": { "isAdmin": true } } }';

// { user: { __proto__: { isAdmin: true } } }
JSON.parse(input);

// { user: {} }
destr(input);

✅ Strict Mode

When 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)

javascript
// Returns "[foo"
destr("[foo");

// Throws an error
safeDestr("[foo");

Benchmarks

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 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.

Check Benchmark Results or run with pnpm run bench:node or pnpm run bench:bun yourself!

License

MIT. Made with

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

TypeScriptdenojsonjsonparsenode

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言