Sha256: 3d190b291d138b6b0aab09b93c66b878373dc2eaaa2b02e81d9ef374c9004068

Contents?: true

Size: 1.12 KB

Versions: 32

Compression:

Stored size: 1.12 KB

Contents

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

Version data entries

32 entries across 18 versions & 3 rubygems

Version Path
hooch-0.4.2 jasmine/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/node_modules/request/node_modules/json-stringify-safe/README.md
hooch-0.4.1 jasmine/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/node_modules/request/node_modules/json-stringify-safe/README.md
hooch-0.4.0 jasmine/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/node_modules/request/node_modules/json-stringify-safe/README.md
hooch-0.3.0 jasmine/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/node_modules/request/node_modules/json-stringify-safe/README.md
hooch-0.2.1 jasmine/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/node_modules/request/node_modules/json-stringify-safe/README.md
hooch-0.2.0 jasmine/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/node_modules/request/node_modules/json-stringify-safe/README.md
hooch-0.1.0 jasmine/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/node_modules/request/node_modules/json-stringify-safe/README.md
hooch-0.0.8 jasmine/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/node_modules/request/node_modules/json-stringify-safe/README.md
hooch-0.0.7 jasmine/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/node_modules/request/node_modules/json-stringify-safe/README.md
hooch-0.0.6 jasmine/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/node_modules/request/node_modules/json-stringify-safe/README.md
entangled-0.0.16 spec/dummy/public/node_modules/bower/node_modules/request/node_modules/json-stringify-safe/README.md
entangled-0.0.16 spec/dummy/public/node_modules/phantomjs/node_modules/request/node_modules/json-stringify-safe/README.md
entangled-0.0.16 spec/dummy/public/node_modules/bower/node_modules/bower-registry-client/node_modules/request/node_modules/json-stringify-safe/README.md
entangled-0.0.15 spec/dummy/public/node_modules/bower/node_modules/bower-registry-client/node_modules/request/node_modules/json-stringify-safe/README.md
entangled-0.0.15 spec/dummy/public/node_modules/bower/node_modules/request/node_modules/json-stringify-safe/README.md
entangled-0.0.15 spec/dummy/public/node_modules/phantomjs/node_modules/request/node_modules/json-stringify-safe/README.md
entangled-0.0.14 spec/dummy/public/node_modules/phantomjs/node_modules/request/node_modules/json-stringify-safe/README.md
entangled-0.0.14 spec/dummy/public/node_modules/bower/node_modules/request/node_modules/json-stringify-safe/README.md
entangled-0.0.14 spec/dummy/public/node_modules/bower/node_modules/bower-registry-client/node_modules/request/node_modules/json-stringify-safe/README.md
entangled-0.0.13 spec/dummy/public/node_modules/bower/node_modules/bower-registry-client/node_modules/request/node_modules/json-stringify-safe/README.md