Skip to content
  • Sponsor
  • Notifications You must be signed in to change notification settings
  • Fork 50

Improve README #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# json-stringify-safe

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

## Usage

@@ -18,10 +18,10 @@ Output:

```json
{
"circularRef": "[Circular]",
"circularRef": "[Circular ~]",
"list": [
"[Circular]",
"[Circular]"
"[Circular ~]",
"[Circular ~]"
]
}
```
@@ -35,11 +35,13 @@ 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.
The default `decycler` function returns a string like `'[Circular ~.a.b]'`
where `~.a.b` represents where the circular reference comes from (`~` being
the stringified object). If, for example, you pass an empty function `(k,v) => {}`
then it will prune cycles. If you pass in `(k,v) => ({ foo: 'bar' })`, then
cyclical objects will always be represented as `{"foo":"bar"}` in the result.
If you pass `() => '[Circular]'`, then every circular reference will be just
`[Circular]` without the `~`-path.

```
stringify.getSerialize(serializer, decycler)