
Security News
Software Engineering Daily Podcast: Feross on AI, Open Source, and Supply Chain Risk
Socket CEO Feross Aboukhadijeh joins Software Engineering Daily to discuss modern software supply chain attacks and rising AI-driven security risks.
fast-stringify
Advanced tools
A tiny, blazing fast stringifier that safely handles circular objects.
The fastest way to stringify an object will always be the native JSON.stringify, but it does not support circular objects out of the box. If you need to stringify objects that have circular references, fast-stringify is there for you! It hsa a simple API to allow for several use-cases that JSON.stringify does not while also maintaining blazing fast performance compared to its peers.
import { stringify } from 'fast-stringify';
const object = {
foo: 'bar',
deeply: {
recursive: {
object: {},
},
},
};
object.deeply.recursive.object = object.deeply.recursive;
console.log(stringify(object));
// {"foo":"bar","deeply":{"recursive":{"object":"[ref=.deeply.recursive]"}}}
interface Options {
circularReplacer?: (key: string, value: any, referenceKey: string) => any;
indent?: number;
replacer?: (key: string, value: any) => any;
stable?: boolean;
stabilizer?: (
entryA: { key: string; value: any },
entryB: { key: string; value: any },
stabilizerOptions: { get: (key: string) => any },
) => any;
}
function stringify(value: any, options?: Options): string;
Stringifies the object passed based on the options passed. The only required value is the value. The additional optons passed will customize how the string is compiled. Available options:
replacer => function to customize how the non-circular value is stringified (see the documentation for JSON.stringify for more details)indent => number of spaces to indent the stringified object for pretty-printing (see the documentation for JSON.stringify for more details)circularReplacer => function to customize how the circular value is stringified (defaults to [ref=##] where ## is the referenceKey)
referenceKey is a dot-separated key list reflecting the nested key the object was originally declared atstable => whether to sort the keys for stabilitystabilizer => function to customize how the stable object is sorted (only applies when stable is true)// ESM
import { stringify } from 'fast-stringify';
// CommonJS
const { stringify } = require('fast-stringify');
ββββββββββββββββββββββββββββββ¬ββββββββββ¬ββββββββββββββββββ
β (index) β Ops/sec β Margin of error β
ββββββββββββββββββββββββββββββΌββββββββββΌββββββββββββββββββ€
β fast-stringify β 1246981 β 'Β± 0.01%' β
β faster-stable-stringify β 1009331 β 'Β± 0.02%' β
β fast-json-stable-stringify β 918643 β 'Β± 0.02%' β
β json-stringify-safe β 736089 β 'Β± 0.02%' β
β json-stable-stringify β 655688 β 'Β± 0.02%' β
β decircularize β 434227 β 'Β± 0.03%' β
β superjson β 260614 β 'Β± 0.03%' β
β json-cycle β 5930 β 'Β± 0.06%' β
ββββββββββββββββββββββββββββββ΄ββββββββββ΄ββββββββββββββββββ
Fastest was "fast-stringify".
ββββββββββββββββββββββββββββββ¬ββββββββββ¬ββββββββββββββββββ
β (index) β Ops/sec β Margin of error β
ββββββββββββββββββββββββββββββΌββββββββββΌββββββββββββββββββ€
β fast-stringify β 182435 β 'Β± 0.04%' β
β fast-json-stable-stringify β 181922 β 'Β± 0.03%' β
β faster-stable-stringify β 164295 β 'Β± 0.03%' β
β json-stringify-safe β 133740 β 'Β± 0.04%' β
β json-stable-stringify β 110923 β 'Β± 0.04%' β
β decircularize β 60097 β 'Β± 0.05%' β
β superjson β 41319 β 'Β± 0.06%' β
β json-cycle β 959 β 'Β± 0.06%' β
ββββββββββββββββββββββββββββββ΄ββββββββββ΄ββββββββββββββββββ
Fastest was "fast-stringify".
ββββββββββββββββββββββββββββββ¬ββββββββββ¬ββββββββββββββββββ
β (index) β Ops/sec β Margin of error β
ββββββββββββββββββββββββββββββΌββββββββββΌββββββββββββββββββ€
β fast-stringify β 154881 β 'Β± 0.04%' β
β fast-json-stable-stringify β 148094 β 'Β± 0.04%' β
β faster-stable-stringify β 139589 β 'Β± 0.04%' β
β json-stringify-safe β 115500 β 'Β± 0.05%' β
β json-stable-stringify β 95238 β 'Β± 0.06%' β
β decircularize β 54071 β 'Β± 0.08%' β
β superjson β 32388 β 'Β± 0.08%' β
β json-cycle β 883 β 'Β± 0.12%' β
ββββββββββββββββββββββββββββββ΄ββββββββββ΄ββββββββββββββββββ
Fastest was "fast-stringify".
ββββββββββββββββββββββββββββββ¬ββββββββββ¬ββββββββββββββββββ
β (index) β Ops/sec β Margin of error β
ββββββββββββββββββββββββββββββΌββββββββββΌββββββββββββββββββ€
β fast-stringify β 68639 β 'Β± 0.06%' β
β json-stringify-safe β 52087 β 'Β± 0.06%' β
β fast-json-stable-stringify β 51025 β 'Β± 0.06%' β
β faster-stable-stringify β 46096 β 'Β± 0.07%' β
β json-stable-stringify β 33479 β 'Β± 0.08%' β
β decircularize β 20333 β 'Β± 0.11%' β
β superjson β 14914 β 'Β± 0.10%' β
β json-cycle β 341 β 'Β± 0.11%' β
ββββββββββββββββββββββββββββββ΄ββββββββββ΄ββββββββββββββββββ
Fastest was "fast-stringify".
ββββββββββββββββββββββββββββββ¬ββββββββββ¬ββββββββββββββββββ
β (index) β Ops/sec β Margin of error β
ββββββββββββββββββββββββββββββΌββββββββββΌββββββββββββββββββ€
β fast-json-stable-stringify β 673986 β 'Β± 0.02%' β
β faster-stable-stringify β 645572 β 'Β± 0.03%' β
β fast-stringify β 524383 β 'Β± 0.02%' β
β json-stable-stringify β 398551 β 'Β± 0.03%' β
ββββββββββββββββββββββββββββββ΄ββββββββββ΄ββββββββββββββββββ
Fastest was "fast-json-stable-stringify".
ββββββββββββββββββββββββββββββ¬ββββββββββ¬ββββββββββββββββββ
β (index) β Ops/sec β Margin of error β
ββββββββββββββββββββββββββββββΌββββββββββΌββββββββββββββββββ€
β fast-json-stable-stringify β 479587 β 'Β± 0.03%' β
β faster-stable-stringify β 477015 β 'Β± 0.03%' β
β fast-stringify β 380990 β 'Β± 0.03%' β
β json-stable-stringify β 288945 β 'Β± 0.03%' β
ββββββββββββββββββββββββββββββ΄ββββββββββ΄ββββββββββββββββββ
Fastest was "fast-json-stable-stringify".
FAQs
A blazing fast stringifier that safely handles circular objects
The npm package fast-stringify receives a total of 39,858 weekly downloads. As such, fast-stringify popularity was classified as popular.
We found that fast-stringify demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.Β It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CEO Feross Aboukhadijeh joins Software Engineering Daily to discuss modern software supply chain attacks and rising AI-driven security risks.

Security News
GitHub has revoked npm classic tokens for publishing; maintainers must migrate, but OpenJS warns OIDC trusted publishing still has risky gaps for critical projects.

Security News
Rustβs crates.io team is advancing an RFC to add a Security tab that surfaces RustSec vulnerability and unsoundness advisories directly on crate pages.