• Stars
    star
    639
  • Rank 70,436 (Top 2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 11 years ago
  • Updated almost 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

JSON compressor and decompressor

JSONC

Update to version 1.6.1

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 is born to change the way browser vendors think and become an standard when send information to the server efficiently.

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 GZIP compression algorithm, to make the job JSONC uses a modification to use the gzip library and it encodes the gzipped string with Base64 to avoid url encode.

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%

Next steps

Implement the gzip class in different languages (Java, Ruby...)

More Repositories

1

Design-Patterns-in-Javascript

Design Patterns applied to Javascript code.
JavaScript
2,618
star
2

javascript-challenges-book

Challenge yourself learning and understanding the most obscure and tricky parts of Javascript. http://tcorral.github.io/javascript-challenges-book/
JavaScript
803
star
3

Refactoring_Patterns

A list of 31 Javascript refactoring patterns, based on the '31 Days of Refactoring' book by Sean Chambers and Simone Chiaretta, with the applied solutions.
JavaScript
227
star
4

Cutter.js

Truncate HTML code to limit its length by number of words without losing markup.
JavaScript
220
star
5

Hydra.js

Create a scalable, maintainable and module oriented system using Hydra.js
JavaScript
102
star
6

IM.js

Image Match - Project to allow compare different images pixel by pixel with good performance
JavaScript
81
star
7

Hermes.js

Message and Error logger implementation
JavaScript
30
star
8

Javascript-Best-Practices

Javascript Best Practices
JavaScript
15
star
9

html-to-wireframe

Tool to generate wireframes from an url or html file with different sizes.
JavaScript
15
star
10

Interface.js

Javascript Interface implementation
8
star
11

eslint-audio-formatter

Audio formatter/reporter for EsLint to get the reports in mp3 files with all the errors and warnings.
JavaScript
7
star
12

CORSET

A new way to break the x-origin policy in scripts allocated in different domains.
HTML
6
star
13

DesignPatterns_code

Code to use in talks about design patterns
JavaScript
6
star
14

Hydra_Extensions

Extensions for use with Hydra.js
JavaScript
6
star
15

TDD_Workshop

Code and slides from the TDD Workshop
JavaScript
5
star
16

swagger2-to-raml

Convert from Swagger 2.0 YAML to RAML 0.8 RAML
JavaScript
5
star
17

St.George-Legend

Transcription of St.George Legend to Javascript
JavaScript
4
star
18

observable-it

Implementation of Observable pattern for browser
JavaScript
4
star
19

CoffeeScript-Syntax-Definition

Syntax Highlight Definition for CoffeeScript to be used in Fisheye or Crucible by Atlassian
4
star
20

Focus.js

Library to set the focus of any element in DOM
JavaScript
4
star
21

HTML5-Storage-Practice

JavaScript
3
star
22

redux-time-machine

Convert your redux in a time machine. Basic to implement do-undo system in your application.
TypeScript
3
star
23

GIT_IRONHACK

2
star
24

ASR-Server-WF3

OpenText frontend framework
JavaScript
2
star
25

Refactoring-Exercise

2
star
26

EventHandler.js

Event handler
JavaScript
2
star
27

ukko-cli

Command line tool to manages the download all the needed repos and build them to have your development environment ready to start working in minutes
JavaScript
2
star
28

ukko

Module that manages the download all the needed repos and build them to have your development environment ready to start working in minutes
Perl
2
star
29

CSSplus

Compile CSS using variables to speed your development
2
star
30

Calendar

Calendar widget class to use on any Javascript code
JavaScript
2
star
31

methodology-angular-development

HTML
1
star
32

FBB

FBB, a.k.a. Frontend Building Blocks is a set of logic components that can be reused in your code to create your own widgets
JavaScript
1
star
33

Marvin.js

Javascript framework
1
star
34

Template

1
star
35

_test_busterjs

Zip file to test in buster.js
1
star
36

junit-reporter

jUnit reporter to use in any tool
JavaScript
1
star
37

ng-extend-test

A repository to test how to extend the different elements of AngularJS
JavaScript
1
star
38

spotiapp-web

HTML
1
star
39

mystiquex

Tool to manage and download different source endpoints
JavaScript
1
star
40

moonwalker

Tool to launch Selenese tests.
JavaScript
1
star
41

sensitive-data-cleaner

NPM package that will remove all sensitive data in package.json or package-lock.json
TypeScript
1
star
42

Koyote.js

Powerful and minimal mixin framework that allows you to be creative.
JavaScript
1
star
43

code2mp3

An experiment to convert any code to mp3 music.
JavaScript
1
star
44

Plant.js

Template System
1
star
45

Enumerable.js

Add Enumerable behaviour to Array
1
star
46

Backbone_Workshop_code

Backbone.js practice and solution code
1
star