Pack json object or array to string by recursively compressing keys only.
npm install @lexriver/json-pack
import {JsonPack} from '@lexriver/json-pack'
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)
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.
Unpack string to object or array.