Encode JSON into compact, readable URL-safe strings

  • juri

Downloads in past


5141.0.38 years ago9 years agoMinified + gzip package size for juri in KB


Encodes JSON objects into compact, human readable strings that are safe for use in URIs.
Juri works with Node.js and with browserify.


npm install juri


Say you have data like this:
{ zh: 
   { name: 'China',
     continent: 'Asia',
     flagColors: [ 'red', 'yellow' ],
     leader: { name: '习 近平-习', title: 'President', term: 137 },
     population: 1370000000 },
   { name: 'India',
     continent: '',
     a: true,
     b: false,
     c: null,
     emptyArray: [],
     emptyObject: {},
     flagColors: [ 'orange', 'white', 'green' ],
     leader: { name: 'Narendra\nModi.', title: 'Prime Minister', term: 119 },
     population: 1190000000 },
  array: [ 'asdf', [ 3, 4 ] ] }

Encode this using juri:
var juri = require("juri")();


to get a string like:

or as a query string (juri.encodeQString(object)):

which are around 55% smaller than the equivalent URL-encoded JSON.
A dictionary of up to 64 commonly repeated strings (e.g. key names, enum values, or even commonly repeated words) can be passed to the encoder and decoder to compress even further, at the cost of reduced human-readability.
For example,
var dictionary = [
	"red", "yellow", "orange", "blue", "green", "white",
	"Asia", "North America", "South America",
	"name", "continent", "flagColors",
	"leader", "title", "term", "population", "平" ];
var juri = require("juri")(dictionary);


This gives:

It’s still somewhat human readable: n is name, c is country etc. This example was compressed to almost 30% of the size of URL-encoded JSON.

Differences from Rison

Juri is similar to Rison but improves upon it in many ways.
  • Strings are unquoted and encoded efficiently instead of relying on percent-
encoding. Spaces are replaced with underscores (not %20), punctuation uses two-byte escape sequences, and runs of non-latin characters are encoded with Base64 which takes about 40% less space than percent-encoding.
  • Numbers are encoded with modified Base64 alphabet whose first 16 characters are
0-9 and A-F. This keeps small numbers human readable while large ones (like timestamps) are represented with 50% fewer bytes. All numbers are prefixed with a sign (+ or -) and use exponent notation where it's shorter.
  • Juri does not require special markers like !(...) to distinguish between
objects and arrays; this saves characters in deeply nested structures and is more readable.