json-in-compress
v1.1.10
Published
JSON Compress
Downloads
8
Readme
JSON Compress
=====
Background
One of the problems you can have developing rich internet applications (RIA) using Javascript is the amount of data being transported to and from the server.
When data comes from server, this data could be GZipped, but this is not possible when the big amount of data comes from the browser to the server.
Gzip - @beatgammit - https://github.com/beatgammit/gzip-js
Base64 - http://www.webtoolkit.info/
Usage
Compress a JSON object:
// Returns a JSON object but compressed.
var compressedJSON = JSONC.compress( json );
Decompress a JSON object:
// Returns the original JSON object.
var json = JSONC.decompress( compressedJSON );
Compress a normal JSON object as a Gzipped string:
// Returns the LZW representation as string of the JSON object.
var lzwString = JSONC.pack( json );
Compress a JSON object as a Gzipped string after compress it using JSONC:
// Returns the LZW representation as string of the JSON object.
var lzwString = JSONC.pack( json, true );
Decompress a normal JSON object from a Gzipped string:
// Returns the original JSON object.
var json = JSONC.unpack( gzippedString );
Decompress a JSON compressed object using JSONC from a Gzipped string:
// Returns the original JSON object.
var json = JSONC.unpack( gzippedString, true );
Examples of compression
Example data.js.
Original - 17331 bytes
Compressed using JSONC - 16025 bytes
Compression rate - 7.5%
Original compressed using gzip.js - 5715 bytes
Compressed using JSONC using gzip.js - 5761 bytes
Compression rate from original to compressed using JSONC and gzip.js - 66.76%
Example data2.js.
Original - 19031 bytes
Compressed using JSONC - 12787 bytes
Compression rate - 32.81%
Original compressed using gzip.js - 4279 bytes
Compressed using JSONC using gzip.js - 4664 bytes
Compression rate from original to compressed using JSONC and gzip.js - 75.49%