Fold
Edit this pageThe fold transform collapses (or “folds”) one or more data fields into two properties: a key property (containing the original data field name) and a value property (containing the data value).
The fold transform is useful for mapping matrix or cross-tabulation data into a standardized format.
This transform generates a new data stream in which each data object consists of the key and value properties as well as all the original fields of the corresponding input data object.
Note: The fold
transform only applies to a list of known fields (set using the fields
parameter). If your data objects instead contain array-typed fields, you may wish to use the flatten transform instead.
// Any View Specification
{
...
"transform": [
{"fold": ...} // Fold Transform
...
],
...
}
Fold Transform Definition
Property | Type | Description |
---|---|---|
fold | String[] |
Required. An array of data fields indicating the properties to fold. |
as | [FieldName, FieldName] |
The output field names for the key and value properties produced by the fold transform. Default value: |
Usage
{"fold": ["gold", "silver"]}
This example folds the "gold"
and "silver"
properties. Given the input data
[
{"country": "USA", "gold": 10, "silver": 20},
{"country": "Canada", "gold": 7, "silver": 26}
]
this example produces the output:
[
{"key": "gold", "value": 10, "country": "USA", "gold": 10, "silver": 20},
{"key": "silver", "value": 20, "country": "USA", "gold": 10, "silver": 20},
{"key": "gold", "value": 7, "country": "Canada", "gold": 7, "silver": 26},
{"key": "silver", "value": 26, "country": "Canada", "gold": 7, "silver": 26}
]