# serialize-json

> A serialize algorithm for JSON

Latest version **1.0.3** (published 2018-10-29) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2018-10-29 |
| First published | 2017-02-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 4.0.0 |
| Dependencies | 3 |
| Unpacked size | 14.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 25 |
| Author | gxcsoccer@126.com |
| Maintainers | gxcsoccer |
| Keywords | json, serialization |

## Links

- npm: https://www.npmjs.com/package/serialize-json
- Repository: https://github.com/node-modules/serialize-json
- Homepage: https://github.com/node-modules/serialize-json#readme
- Issues: https://github.com/node-modules/serialize-json/issues
- npm.io page: https://npm.io/package/serialize-json

## Dependencies (3)

- [debug](https://npm.io/package/debug.md) ^3.2.6
- [utility](https://npm.io/package/utility.md) ^1.15.0
- [is-type-of](https://npm.io/package/is-type-of.md) ^1.2.1

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

- 1.0.3 (latest) — 2018-10-29
- 1.0.2 — 2017-09-22
- 1.0.1 — 2017-02-08
- 1.0.0 — 2017-02-06

## README

# serialize-json
A serialize algorithm for JSON

[![NPM version][npm-image]][npm-url]
[![build status][travis-image]][travis-url]
[![Test coverage][codecov-image]][codecov-url]
[![David deps][david-image]][david-url]
[![Known Vulnerabilities][snyk-image]][snyk-url]
[![npm download][download-image]][download-url]

[npm-image]: https://img.shields.io/npm/v/serialize-json.svg?style=flat-square
[npm-url]: https://npmjs.org/package/serialize-json
[travis-image]: https://img.shields.io/travis/node-modules/serialize-json.svg?style=flat-square
[travis-url]: https://travis-ci.org/node-modules/serialize-json
[codecov-image]: https://codecov.io/gh/node-modules/serialize-json/branch/master/graph/badge.svg
[codecov-url]: https://codecov.io/gh/node-modules/serialize-json
[david-image]: https://img.shields.io/david/node-modules/serialize-json.svg?style=flat-square
[david-url]: https://david-dm.org/node-modules/serialize-json
[snyk-image]: https://snyk.io/test/npm/serialize-json/badge.svg?style=flat-square
[snyk-url]: https://snyk.io/test/npm/serialize-json
[download-image]: https://img.shields.io/npm/dm/serialize-json.svg?style=flat-square
[download-url]: https://npmjs.org/package/serialize-json

## Introduction

- Support serialize JSON to Buffer, and deserialize Buffer to JSON
  - [√] Boolean
  - [√] String
  - [√] Number
  - [√] Null
  - [√] Undefined
  - [√] Date
  - [√] Buffer
  - [√] Error
  - [√] Plain Object
  - [×] Function
  - [×] RegExp
  - [×] Symbol

- Inspire by [jsonpack](https://github.com/sapienlab/jsonpack), it can compress to 55% of original size if the data has a recursive structure

## Install

```bash
$ npm install serialize-json --save
```

Node.js >= 4.0.0 required

## Usage

```js
let json = {
  a: 'a',
  b: 123,
  c: 123.456,
  d: [ 1, 2, 3 ],
  e: true,
  f: null,
  g: undefined,
  h: new Date(),
  i: new Buffer('this is a buffer'),
  j: new Error('this is a error'),
};
const buf = JSON.encode(json);
const result = JSON.decode(buf);
assert.deepEqual(result, json);
```

## API

- `encode(json)` serialize a json object
- `decode(buf)` deserialize a buffer to json

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