# commonform-serialize

> serialize Common Forms

Latest version **2.0.0** (published 2026-09-05) · BlueOak-1.0.0 license · 0 weekly downloads

## Install

```sh
npm install commonform-serialize
pnpm add commonform-serialize
yarn add commonform-serialize
bun add commonform-serialize
```

## Health

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

Positive: esm support; no vulnerabilities; recently updated.

Warnings: low downloads; no types.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2026-09-05 |
| First published | 2015-02-05 |
| Weekly downloads | 0 |
| License | BlueOak-1.0.0 |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 4.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Kyle E. Mitchell |
| Maintainers | kemitchell |
| Keywords | contracts, document assembly, knowledge management, law, serialization |

## Links

- npm: https://www.npmjs.com/package/commonform-serialize
- Repository: https://github.com/commonform/commonform-serialize
- Homepage: https://commonform.github.io
- Issues: https://github.com/commonform/commonform-serialize/issues
- npm.io page: https://npm.io/package/commonform-serialize

## Dependencies (2)

- [is-array](https://npm.io/package/is-array.md) ^1.0.1
- [is-object](https://npm.io/package/is-object.md) ^1.0.1

## Alternatives

- [@cantoo/pdf-lib](https://npm.io/package/@cantoo/pdf-lib.md) — 297.9K weekly downloads
- [datatables.net-buttons](https://npm.io/package/datatables.net-buttons.md) — 200.1K weekly downloads
- [@ckeditor/ckeditor5-export-pdf](https://npm.io/package/@ckeditor/ckeditor5-export-pdf.md) — 167.0K weekly downloads
- [scanbot-web-sdk](https://npm.io/package/scanbot-web-sdk.md) — 15.0K weekly downloads
- [@syncfusion/ej2-angular-pdfviewer](https://npm.io/package/@syncfusion/ej2-angular-pdfviewer.md) — 8.8K weekly downloads

## Recent versions

- 2.0.0 (latest) — 2026-09-05
- 1.0.0 — 2019-05-29
- 0.4.6 — 2016-09-11
- 0.4.5 — 2016-02-25
- 0.4.4 — 2016-02-14
- 0.4.3 — 2016-02-14
- 0.4.2 — 2015-08-31
- 0.4.1 — 2015-08-31
- 0.4.0 — 2015-04-15
- 0.2.0 — 2015-02-21
- 0.1.0 — 2015-02-05

## README

# commonform-serialize

serialize Common Forms

This package defines a uniform, deterministic way to serialize Common Form objects, so they can be [hashed](https://www.npmjs.com/package/commonform-hash) consistently.

```javascript
import * as serialize from 'commonform-serialize'
```

Sorts object keys:

```javascript
import assert from 'node:assert'

assert.deepEqual(
  serialize.stringify({ a: '1', b: '2' }),
  serialize.stringify({ b: '2', a: '1' })
)
```

Outputs valid JSON `String`, `Object`, and `Array`:

```javascript
const a1 = { a: '1' }
assert.deepEqual(
  JSON.parse(serialize.stringify(a1)),
  a1
)

const a12 = { a: [ '1', '2' ] }
assert.deepEqual(
  JSON.parse(serialize.stringify(a12)),
  a12
)

const aEmpty = { a: [ ] }
assert.deepEqual(
  JSON.parse(serialize.stringify(aEmpty)),
  aEmpty
)
```

Escapes quotation marks:

```javascript
assert.deepEqual(
  serialize.stringify({ a: '"this is a test"' }),
  '{"a":"\\"this is a test\\""}'
)
```

Throw errors for non-`String`, non-`Object`, non-`Array` content:

```javascript
const invalidValues = {
  boolean: true,
  number: 1,
  null: null,
  undefined: void 0
}

Object.getOwnPropertyNames(invalidValues).map(function (type) {
  assert.throws(
    function () {
      serialize.stringify({ a: invalidValues[type] })
    },
    /argument to stringify contains other than object, array, or string/
  )
})
```

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