Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

serialize-json

node-modules103.5kMIT1.0.3

A serialize algorithm for JSON

json, serialization

readme

serialize-json

A serialize algorithm for JSON

NPM version build status Test coverage David deps Known Vulnerabilities npm download

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, it can compress to 55% of original size if the data has a recursive structure

Install

$ npm install serialize-json --save

Node.js >= 4.0.0 required

Usage

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

changelog

1.0.3 / 2018-10-29

fixes

others

1.0.2 / 2017-09-22

  • refactor: enhance encode/decode large array performance (#4)

1.0.1 / 2017-02-09

  • fix: support encode object without prototype (#2)

1.0.0 / 2017-02-06

  • feat: implement a serialize algorithm for JSON