# @oresoftware/safe-stringify

> Safely stringify objects with recursive references.

Latest version **0.1.13** (published 2026-06-03) · SEE LICENSE IN LICENSE.md license · 0 weekly downloads

## Install

```sh
npm install @oresoftware/safe-stringify
pnpm add @oresoftware/safe-stringify
yarn add @oresoftware/safe-stringify
bun add @oresoftware/safe-stringify
```

## Health

**Score 55/100 (C)** — status: active.

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

Warnings: low downloads; no esm support; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.1.13 |
| Published | 2026-06-03 |
| First published | 2018-08-15 |
| Weekly downloads | 0 |
| License | SEE LICENSE IN LICENSE.md |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 10 KB |
| Known vulnerabilities | 0 |
| Install scripts | yes |
| Author | TODO Yo.Mama |
| Maintainers | oresoftware |
| Keywords | typescript, library, skeleton, scaffold |

## Links

- npm: https://www.npmjs.com/package/@oresoftware/safe-stringify
- Repository: https://github.com/ORESoftware/typescript-library-skeleton
- Homepage: https://github.com/ORESoftware/typescript-library-skeleton#readme
- Issues: https://github.com/ORESoftware/typescript-library-skeleton/issues
- npm.io page: https://npm.io/package/@oresoftware/safe-stringify

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 0.1.13 (latest) — 2026-06-03
- 0.1.12 — 2025-09-02
- 0.0.111 — 2019-09-26
- 0.0.109 — 2019-09-25
- 0.0.108 — 2019-09-10
- 0.0.107 — 2019-09-04
- 0.0.1006 — 2019-04-11
- 0.0.1005 — 2018-12-15
- 0.0.1004 — 2018-12-09
- 0.0.1003 — 2018-12-09
- 0.0.1002 — 2018-12-08
- 0.0.1001 — 2018-08-15

## README

[![Version](https://img.shields.io/npm/v/@oresoftware/safe-stringify.svg?colorB=green)](https://www.npmjs.com/package/@oresoftware/safe-stringify)

# @oresoftware/safe-stringify


####  Motivation/purpose for this library:

> [See this Github gist](https://gist.github.com/ORESoftware/10bd74e27728a2aa764df4d6c6ecada8) 


###  Installation:

>
>```bash
> $ npm i -S '@oresoftware/safe-stringify'
>```
>

##  For most objects (this is more performant)

```js
import * as safe from '@oresoftware/safe-stringify';
const s = safe.stringify({});
```

##  For use with more complex deeply-nested objects with arrays:


Note: stringifyDeep is *not* production ready, please don't use it yet, 
without improving it and making sure it works for you.


```js
import * as safe from '@oresoftware/safe-stringify';
const s = safe.stringifyDeep([{}]);
```

For example the following works with `stringifyDeep` but not `stringify`:

```js
const x = {dog:'bark'};
x.mmm = {'zebra': 3};
x.mmm = x;

const v = [x,x,x];
v.zzz = v;
v.foo = 5;
v.dog = 3;

const mmm = safe.stringifyDeep([v,v,v]);
console.log(mmm);

```


## > Using Map and Set, etc

This library does not treat Map and Set or other classes as special. To serialize a Map or Set instance, 
you might do:

```js

class HasMapAndSet {
  
  constructor(){
    this.map = new Map([['one',1], ['two',2]]);
    this.set = new Set([1,2,3]);
  }
   
  toJSON(){  // use this to transform Map and Set to {} or []
    return {
      map: Array.from(this.map),
      set: Array.from(this.set)
    }
  }
  
}


console.log(
  JSON.stringify(
    new HasMapAndSet()
  )
);

```

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