Unpacker

Unpacker transforms a character-efficient compact object into a developer-friendly expanded object, through the following features:

Variable Index

The variable index is defined in the compact object with the key ?. In the example below we define two pieces of data and refer to them elsewhere in the object to provide contact information for a company. References to %0 resolve to the first object in the variable index: abccompany, references to %1 resolve to the second object in the variable index +4412345678.

Click the "Expanded" tab to see the Expanded Object, notice the Variable Index is removed:

{ "?": [ "abccompany", "+4412345678"], "coname" : "ABC Company Ltd", "telephone" : [ { "label" : "Accounts", "number" : "%1%90" }, { "label" : "Customer Service", "number" : "%1%89" } ], "twitter" : "/%0", "instagram" : "/%0%pics" }
  • Compact
  • Expanded

Substitution Object

Values in the Substitution Object can be referenced in the Compact Object. For example, given the following Substitution Object:

{ "cs": "Customer Service", "ac" : "Accounts" }
A simple Substitution Object

These values can be referenced in the Compact Object in a similar way to the Variable Index, using the key name:

{ "?": [ "abccompany", "+4412345678"], "coname" : "ABC Company Ltd", "telephone" : [ { "label" : "%ac", "number" : "%1%90" }, { "label" : "%cs", "number" : "%1%89" } ], "twitter" : "/%0", "instagram" : "/%0%pics" }
  • Compact
  • Expanded

The Substitution Object is useful when you have data repeated across many different Compact Objects.

Transformation Object

The Transformation Object is a set of instructions to unpack our Compact Object. For example, the following Transformation Object instructs unpacker to rewrite short keys to their developer-friendly version (TODO: Unpacker currently doesn't expand l and n:

{ "c" : { "rewriteKey" : "coname" }, "t" : { "rewriteKey" : "telephone" }, "l" : { "rewriteKey" : "label" }, "n" : { "rewriteKey" : "number" }, "tw" : { "rewriteKey" : "twitter" }, "i" : { "rewriteKey" : "instagram" } }
A Transformation Object to unpack shorter keys into more developer-friendly versions

Now we can reduce our Compact Object further:

{ "?": [ "abccompany", "+4412345678"], "c" : "ABC Company Ltd", "t" : [ { "l" : "%ac", "n" : "%1%90" }, { "l" : "%cs", "n" : "%1%89" } ], "tw" : "/%0", "i" : "/%0%pics" }
  • Compact
  • Expanded

In this short and simple example, we've demonstrated how to unpack a compact object of 136 characters into a developer-friendly expanded object of 194 characters, we have reduced the storage size of our object by 30%.

The Transformation Object can do much more than just rewrite keys, for example:

Learn More

To see a full Worked Example of how Unpacker can be used click Worked Example. To experiment with Unpacker use the Playground, to get started on your own project take a look at the Developer Libraries.