The fold transform collapses (or “folds”) one or more data fields into two properties: akey property (containing the original data field name) and avalue 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 thekey andvalue properties as well as all the original fields of the corresponding input data object.
Note: Thefold
transform only applies to a list of known fields (set using thefields
parameter). If your data objects instead contain array-typed fields, you may wish to use theflatten transform instead.
// Any View Specification{ ... "transform": [ {"fold": ...} // Fold Transform ... ], ...}
Property | Type | Description |
---|---|---|
fold | String[] | Required. An array of data fields indicating the properties to fold. |
as | String[] | The output field names for the key and value properties produced by the fold transform.Default value: |
{"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}]