The components of Unpacker are:
- Compact Object – the data in its most compact form. Required.
- Substitution Object – reduce repeating data across objects by storing it once and referring to in many Compact Objects. Optional.
- Transformation Object – contains instructions to transform the Compact Object. Optional.
- Expanded Object – the result of the Unpacker process.
This object is required and may include a Variable Index:
Reduce repeated data in your Compact Object by defining it once and referring to it multiple times in the same object. The Variable Index can only be defined at the root of the Compact Object using the
? key. The Variable Index never appears in the Expanded Object.
Variables are stored as array items and referenced using their array position:
The Variable Index may include maps and arrays:
Any item in the Variable Index can be referred to specifically using deep referencing:
Reduce repeated data across objects by storing common data in a Substitution Object and referring to it in many Compact Objects. Keys in the substitution object must not be numbers:
As with the Variable Index, you can use deep referencing to refer to items in the Substitution Object:
The Transformation Object is the most powerful component of Unpacker with many options available to transform the Compact Object. Each pair in the Transformation Object provides a set of instructions on how to transform the corresponding pair in the Compact Object.
Keys at the top level of the Transformation Object are global instructions and will transform all matching keys at any level of the Compact Object. This example uses the
rewriteKey instruction to rewrite all keys named
t in the Compact Object:
Nested keys in the Transformation Object will transform corresponding keys in the Compact Object and override any global instructions:
As shown in the examples above,
rewriteKey instructs Unpacker to change the key of a pair in the Compact Object.
rewriteValue instruction instructs Unpacker to change the value of a pair in the Compact Object. The keyword
%self can be used to refer to the original value.
Augment a value
Restructure a value
replacePair instruction instructs Unpacker to replace the pair identified by the key with the contents of
assignKeys instruction takes an array of values and transforms it into an object by assigning each value with a key:
arrayItems instruction takes an array of arrays and transforms each nested array into an object, enabling key assignment for each of them.
The Expanded Object is simply the result of the Unpacker process. It never includes the Variable Index
References are encapsulated in
%, with the closing
% not required if followed by a space or terminator (
"). In the example below we demonstrate the different ways a value can be referenced:
To reference a value within an array or map, use dot notation. In the example below,
y reference a value within the Variable Index and
z references a value in the Substitution Object:
Each object has its own referencing scope.
Numeric references in the Compact Object always refer to the Variable Index , non-numeric references always refer to the Substitution Object . The Compact Object can't reference any part of itself other than the Variable Index.
References are not allowed in the Substitution Object.
References in the Transformation Object are for values passed through from the Compact Object:
Or for keys assigned in the Transformation Object:
The Transformation Object can reference specific parts of the Compact Object and Substitution Object using the namespace
/subs respectively, for example: