# json-stringify-safe

> Like JSON.stringify, but doesn't blow up on circular refs.

Latest version **5.0.1** (published 2015-05-19) · ISC license · 0 weekly downloads

## Install

```sh
npm install json-stringify-safe
pnpm add json-stringify-safe
yarn add json-stringify-safe
bun add json-stringify-safe
```

## Health

**Score 23/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 5.0.1 |
| Published | 2015-05-19 |
| First published | 2013-02-19 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | separate (@types/json-stringify-safe) |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 554 |
| Author | Isaac Z. Schlueter |
| Maintainers | isaacs, moll |
| Keywords | json, stringify, circular, safe |

## Links

- npm: https://www.npmjs.com/package/json-stringify-safe
- Repository: https://github.com/isaacs/json-stringify-safe
- Issues: https://github.com/isaacs/json-stringify-safe/issues
- npm.io page: https://npm.io/package/json-stringify-safe

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 5.0.1 (latest) — 2015-05-19
- 5.0.0 — 2013-08-02
- 4.0.0 — 2013-03-13
- 3.0.0 — 2013-02-19
- 2.0.0 — 2013-02-19

## README

# json-stringify-safe

Like JSON.stringify, but doesn't throw on circular references.

## Usage

Takes the same arguments as `JSON.stringify`.

```javascript
var stringify = require('json-stringify-safe');
var circularObj = {};
circularObj.circularRef = circularObj;
circularObj.list = [ circularObj, circularObj ];
console.log(stringify(circularObj, null, 2));
```

Output:

```json
{
  "circularRef": "[Circular]",
  "list": [
    "[Circular]",
    "[Circular]"
  ]
}
```

## Details

```
stringify(obj, serializer, indent, decycler)
```

The first three arguments are the same as to JSON.stringify.  The last
is an argument that's only used when the object has been seen already.

The default `decycler` function returns the string `'[Circular]'`.
If, for example, you pass in `function(k,v){}` (return nothing) then it
will prune cycles.  If you pass in `function(k,v){ return {foo: 'bar'}}`,
then cyclical objects will always be represented as `{"foo":"bar"}` in
the result.

```
stringify.getSerialize(serializer, decycler)
```

Returns a serializer that can be used elsewhere.  This is the actual
function that's passed to JSON.stringify.

**Note** that the function returned from `getSerialize` is stateful for now, so
do **not** use it more than once.

---
_Source: https://npm.io/package/json-stringify-safe · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
