Skip to main content

$$map

Returns a mapped array applying the transformer on each of the elements

Usage​

{ 
"$$map": /* Array of elements */,
"to": /* Transformer(##current,##index) */
}
"$$map(<to>):{input}"
note

Alternative form is available using

{
"$$map": [ /* values */, /* to */ ]
}

If to is used, the primary argument is treated only as values

Returns​

array - of type of to's result

Arguments​

ArgumentTypeValuesRequired / Default ValueDescription
PrimaryarrayYesArray of elements
toTransformer(##current,##index)YesTransformer to map each element to its value in the result array
  • ##current - Current element
  • ##index - Current index

Examples​

Input

Definition

Output

{
"value": 5,
"item": {
"foo": "aaa",
"id": "bbb"
},
"items": [
{
"foo": "bar",
"id": "aaa"
},
{
"foo": "bar2",
"id": "bbb"
}
]
}
{
"$$map": "$.items",
"to": {
"id": "##current.id",
"map_foo": "##current.foo",
"idx": "##index",
"value": "$.value"
}
}
[
{
"id": "aaa",
"map_foo": "bar",
"idx": 0,
"value": 5
},
{
"id": "bbb",
"map_foo": "bar2",
"idx": 1,
"value": 5
}
]
{
"value": 5,
"item": {
"foo": "aaa",
"id": "bbb"
},
"items": [
{
"foo": "bar",
"id": "aaa"
},
{
"foo": "bar2",
"id": "bbb"
}
]
}
{
"$$map": [
"$.items",
{
"id": "##current.id",
"map_foo": "##current.foo",
"idx": "##index",
"value": "$.value"
}
]
}
[
{
"id": "aaa",
"map_foo": "bar",
"idx": 0,
"value": 5
},
{
"id": "bbb",
"map_foo": "bar2",
"idx": 1,
"value": 5
}
]
{
"value": 5,
"item": {
"foo": "aaa",
"id": "bbb"
},
"items": [
{
"foo": "bar",
"id": "aaa"
},
{
"foo": "bar2",
"id": "bbb"
}
]
}
{
"$$map": [
"$.item",
{
"id": "##current.id",
"map_foo": "##current.foo",
"idx": "##index",
"value": "$.value"
}
]
}
null
{
"a": [
1,
2
],
"b": [
2,
4
]
}
{
"$$map": [
[
"$.a",
"$.b"
],
"##current[1]"
]
}
[
2,
4
]
[
{
"a": 10
},
{
"a": 11
},
{
"a": 12
}
]
"$$map(##current.a):$"
[
10,
11,
12
]