{"name":"safe-stringify","version":"1.3.0","description":"Serialize objects to JSON with handling for circular references","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/safe-stringify.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"type":"module","exports":{"types":"./index.d.ts","default":"./index.js"},"sideEffects":false,"engines":{"node":">=16"},"scripts":{"test":"xo && ava && tsd"},"keywords":["json","stringify","safe","circular","destroy","serialize","encode","cyclic","object"],"devDependencies":{"ava":"^6.1.3","tsd":"^0.31.1","xo":"^0.58.0"},"gitHead":"f28d20bfa94c97f481b715a3df272e1f0196c029","types":"./index.d.ts","_id":"safe-stringify@1.3.0","bugs":{"url":"https://github.com/sindresorhus/safe-stringify/issues"},"homepage":"https://github.com/sindresorhus/safe-stringify#readme","_nodeVersion":"25.3.0","_npmVersion":"11.7.0","dist":{"integrity":"sha512-gX28YjHEpEpgMeOFD4txJYhoQSNpRUK9AtY3X0R2XtG+AZBwubM5/O9+wKbhyWlTITGfQ3vifeuk/e1/FHWTIw==","shasum":"e162666bf29794281593a812e5c647101f669017","tarball":"http://registry-npm.ywwl.com/safe-stringify/download/safe-stringify-1.3.0.tgz","fileCount":5,"unpackedSize":5699,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIEJ4y5/t0iMgFXJqXQQkapwa4lc1jygGqHBClDmpVxBFAiEA77YNnoGUblQn4fxtJ4aYaEtaGfKNdzLBLT3KEor+S4g="}],"size":2562,"noattachment":false,"key":"/safe-stringify/-/safe-stringify-1.3.0.tgz"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"directories":{},"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/safe-stringify_1.3.0_1770044919927_0.1380745902610152"},"_hasShrinkwrap":false,"readme":"# safe-stringify\n\n> Serialize objects to JSON with handling for circular references\n\n`JSON.stringify()` throws an error if the object contains circular references. This package replaces circular references with `\"[Circular]\"`.\n\n## Install\n\n```sh\nnpm install safe-stringify\n```\n\n## Usage\n\n```js\nimport safeStringify from 'safe-stringify';\n\nconst foo = {a: true};\nfoo.b = foo;\n\nconsole.log(safeStringify(foo));\n//=> '{\"a\":true,\"b\":\"[Circular]\"}'\n\nconsole.log(JSON.stringify(foo));\n//=> TypeError: Converting circular structure to JSON\n\n```\n\n## API\n\n### safeStringify(value, options?)\n\nReturns a string.\n\n*Note: There is no `replacer` option as I didn't need that, but “pull request welcome” if you need it.*\n\n#### value\n\nType: `unknown`\n\nThe value to convert to a JSON string.\n\n#### options\n\nType: `object`\n\n##### indentation\n\nType: `'string' | 'number'`\n\nThe indentation of the JSON.\n\nBy default, the JSON is not indented. Set it to `'\\t'` for tab indentation or the number of spaces you want.\n\n##### trace\n\nType: `boolean`\n\nInclude the full object path in circular reference markers, like `[Circular *a.b]`.\n\n```js\nimport safeStringify from 'safe-stringify';\n\nconst bar = {a: {b: {}}};\nbar.a.b.c = bar.a;\n\nconsole.log(safeStringify(bar, {trace: true}));\n//=> '{\"a\":{\"b\":{\"c\":\"[Circular *a]\"}}}'\n```\n\n## FAQ\n\n### Why another safe stringify package?\n\nThe 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.\n\n## Related\n\n- [decircular](https://github.com/sindresorhus/decircular) - Remove circular references from objects\n","publish_time":1770044920065,"_cnpm_publish_time":1770044920065,"dist-tags":{"latest":"1.3.0"}}