@lexriver/json-pack
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

json-pack

Pack json object or array to string by recursively compressing keys only.

Install

npm install @lexriver/json-pack

Import

import {JsonPack} from '@lexriver/json-pack'

Usage

    const original = [
        {firstName:'John', lastName:'Smith'},
        {firstName:'Anders', lastName: 'Hejlsberg'}
    ]
    const packedString = JsonPack.pack(original)
    console.log('packedString=', packedString) // JsonPack:{"keys":[["firstName","0"],["lastName","1"]],"data":[{"0":"John","1":"Smith"},{"0":"Anders","1":"Hejlsberg"}]}

    const unpacked = JsonPack.unpack(packedString)
    console.log('unpacked=', unpacked)

Methods

JsonPack.pack(o):string

Pack json object to string. The only argument o must be of type Object or Array. Only same keys for object are compressed, not the values.

Returns string.


JsonPack.unpack(packedString:string)

Unpack string to object or array.


Package Sidebar

Install

npm i @lexriver/json-pack

Weekly Downloads

2

Version

1.0.2

License

MIT

Unpacked Size

21.6 kB

Total Files

16

Last publish

Collaborators

  • lexriver