Skip to main content

$map

$map(array, function) -> array
Compact type signature<af>

Source: JSONata

Documentation​

Applies a mapping function to each item in an input sequence and returns the collected results.

The callback receives the current value, index, and source array. Mapped results that are undefined are omitted from the returned sequence. This local implementation expects an array or sequence input; it does not add the singleton-value coercion that FUME uses for $first(), $pMap(), and $pLimit().

Examples​

Compute line totals with a mapping function​

Input

This example uses the claims-lines example input. The expression maps across the claim lines to compute line totals.

Example input

JSON
[
{
"claimId": "clm-2001",
"lineNumber": 1,
"serviceCode": "PROC-010",
"serviceDisplay": "office visit",
"units": 1,
"unitPrice": 125,
"allowedAmount": 110,
"modifiers": [
"MOD-A"
]
},
{
"claimId": "clm-2001",
"lineNumber": 2,
"serviceCode": "PROC-020",
"serviceDisplay": "imaging study",
"units": "1",
"unitPrice": 350,
"allowedAmount": 300,
"modifiers": [
"MOD-B",
"MOD-C"
]
},
{
"claimId": "clm-2001",
"lineNumber": 3,
"serviceCode": "PROC-030",
"serviceDisplay": "lab panel",
"units": 2,
"unitPrice": 40,
"allowedAmount": 70,
"modifiers": []
},
{
"claimId": "clm-2002",
"lineNumber": 1,
"serviceCode": "PROC-010",
"serviceDisplay": "office visit",
"units": 1,
"unitPrice": 125,
"allowedAmount": 115,
"modifiers": [
"MOD-A"
]
},
{
"claimId": "clm-2002",
"lineNumber": 2,
"serviceCode": "PROC-040",
"serviceDisplay": "counseling",
"units": 3,
"unitPrice": 60,
"allowedAmount": 150,
"modifiers": [
"MOD-D"
]
}
]

Expression

$map($, function($l) { $number($l.units) * $l.unitPrice })

Result

[125, 350, 80, 125, 180]