GithubHelp home page GithubHelp logo

jsonc's Introduction

JSONC

Update to version 1.0.0

Build Status

Changelog

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.

JSONC has two differents approaches to reduce the size of the amount of data to be transported:

  • JSONC.compress - Compress JSON objects using a map to reduce the size of the keys in JSON objects.
    • Be careful with this method because it's really impressive if you use it with a JSON with a big amount of data, but it could be awful if you use it to compress JSON objects with small amount of data because it could increase the final size.
    • The rate compression could variate from 7.5% to 32.81% depending of the type and values of data.
  • JSONC.pack - Compress JSON objects using LZW compression algorithm, to make the job JSONC uses the lz-string library from @pieroxy - https://github.com/pieroxy/lz-string/
    • You can use pack to compress any JSON objects even if these objects are not been compressed using JSONC See Usage for more details.

##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 LZW string:

// Returns the LZW representation as string of the JSON object.
var lzwString = JSONC.pack( json );

####Compress a JSON object as a LZW 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 LZW string:

// Returns the original JSON object.
var json = JSONC.unpack( lzwString );

####Decompress a JSON compressed object using JSONC from a LZW string:

// Returns the original JSON object.
var json = JSONC.unpack( lzwString, true );

Examples of compression

####Example data.js.

Original - 17331 bytes
Compressed using JSONC - 16025 bytes
Compression rate - 7.5%


Original compressed using lz-string - 3822 bytes
Compressed using JSONC using lz-string - 3689 bytes
Compression rate - 3.4%


Compression rate from original to compressed using JSONC and lz-string - 78.71%

####Example data2.js.

Original - 19031 bytes
Compressed using JSONC - 12787 bytes
Compression rate - 32.81%


Original compressed using lz-string - 3900 bytes
Compressed using JSONC using lz-string - 3113 bytes
Compression rate - 20.18%


Compression rate from original to compressed using JSONC and lz-string - 83.64%

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.