
Research
/Security News
Contagious Interview Campaign Escalates With 67 Malicious npm Packages and New Malware Loader
North Korean threat actors deploy 67 malicious npm packages using the newly discovered XORIndex malware loader.
safe-stringify
Advanced tools
Serialize objects to JSON with handling for circular references
JSON.stringify()
throws an error if the object contains circular references. This package replaces circular references with "[Circular]"
.
npm install safe-stringify
import safeStringify from 'safe-stringify';
const foo = {a: true};
foo.b = foo;
console.log(safeStringify(foo));
//=> '{"a":true,"b":"[Circular]"}'
console.log(JSON.stringify(foo));
//=> TypeError: Converting circular structure to JSON
Returns a string.
Note: There is no replacer
option as I didn't need that, but “pull request welcome” if you need it.
Type: unknown
The value to convert to a JSON string.
Type: object
Type: 'string' | 'number'
The indentation of the JSON.
By default, the JSON is not indented. Set it to '\t'
for tab indentation or the number of spaces you want.
The existing ones either did too much, did it incorrectly, or used inefficient code (not using WeakSet
). For example, many packages incorrectly replaced all duplicate objects, not just circular references, and did not handle circular arrays.
FAQs
Serialize objects to JSON with handling for circular references
The npm package safe-stringify receives a total of 22,079 weekly downloads. As such, safe-stringify popularity was classified as popular.
We found that safe-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.
Research
/Security News
North Korean threat actors deploy 67 malicious npm packages using the newly discovered XORIndex malware loader.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.