Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/node-modules/serialize-json
A serialize algorithm for JSON
https://github.com/node-modules/serialize-json
json nodejs serialization
Last synced: 16 days ago
JSON representation
A serialize algorithm for JSON
- Host: GitHub
- URL: https://github.com/node-modules/serialize-json
- Owner: node-modules
- License: mit
- Created: 2017-02-03T14:18:58.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2023-01-06T18:00:04.000Z (almost 2 years ago)
- Last Synced: 2024-09-30T00:46:43.018Z (about 1 month ago)
- Topics: json, nodejs, serialization
- Language: JavaScript
- Homepage:
- Size: 14.6 KB
- Stars: 23
- Watchers: 14
- Forks: 4
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: History.md
- License: LICENSE
Awesome Lists containing this project
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