Spread
Transformers have a special spread "key operator": *
.
When "*"
is used in a transformer as a key inside an object, it will copy all the entries from the resolved object of its value before adding the keys in the spec.
Example​
Input
{
"base": {
"language": "en"
}
}
Definition
{
"*": "$.base",
"hello": "world"
}
Output
{
"language": "en",
"hello": "world"
}
Remove keys​
The spread operation can be used to remove keys, here is an example:
Input
{
"base": {
"id": "short id",
"name": "short name",
"description": "some very long description"
}
}
Definition
{
"*": "$.base",
"description": "#null"
}
Output
{
"id": "short id",
"name": "short name"
}
Notice we use #null
to select the keys we want to remove, in this case description
.
Multiple sources​
You can specify more than one source by setting the value to an array:
{
"*": ["$.base1", "$.base2"],
"hello": "world"
}
Merge process will be operated in order of array (with the local keys set last as overrides)
This much resembles the ...
spread operator in ECMAScript:
result = {
...base1,
...base2,
hello: "world"
}