Unpacker
Unpacker transforms a character-efficient compact object into a developer-friendly expanded object, through the following features:
- Variable Index – reduce repeating data in your object by defining it once and referring to it multiple times .
- Substitution Object – define globally common data once and refer to it in many different compact objects.
- Transformation Object – simple but powerful instructions that tell Unpacker how to expand your compact object.
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:
- Compact
Substitution Object
Values in the Substitution Object can be referenced in the Compact Object. For example, given the following Substitution Object:
These values can be referenced in the Compact Object in a similar way to the Variable Index, using the key name:
- Compact
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
:
Now we can reduce our Compact Object further:
- Compact
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:
- Rewrite values
- Rewrite pairs
- Assign keys to values
- Convert arrays to objects
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.