Other Operators
& (Concatenation)
The string concatenation operator is used to join the string values of the operands into a single resultant string. If either or both of the operands are not strings, then they are first cast to string using the rules of the $string function.
Example
Input
This example uses the full claim-batch example input. The next two examples read fields from that document to demonstrate concatenation and conditional evaluation.
Example input
{
"claimId": "clm-9001",
"memberId": "mbr-3001",
"claimLines": [
{
"lineNumber": 1,
"serviceDisplay": "office visit",
"allowedAmount": 110,
"modifiers": [
"MOD-A"
],
"units": 1,
"unitPrice": 125
},
{
"lineNumber": 2,
"serviceDisplay": "imaging study",
"allowedAmount": 300,
"modifiers": [
"MOD-B",
"MOD-C"
],
"units": 1,
"unitPrice": 350
},
{
"lineNumber": 3,
"serviceDisplay": "counseling",
"allowedAmount": 150,
"modifiers": [],
"units": 3,
"unitPrice": 60
},
{
"lineNumber": 4,
"serviceDisplay": "lab panel",
"allowedAmount": 70,
"modifiers": [
"MOD-A"
],
"units": 2,
"unitPrice": 40
}
]
}
Expression:
claimId & "-L" & claimLines[1].lineNumber
Result:
"clm-9001-L2"
? : (Conditional)
The conditional ternary operator is used to evaluate one of two alternative expressions based on the result of a predicate (test) condition. The operator takes the form:
<test_expr> ? <expr_T> : <expr_F>
The <test_expr> expression is first evaluated. If it evaluates to Boolean true, then the operator returns the result of evaluating the <expr_T> expression. Otherwise it returns the result of evaluating the <expr_F> expression. If <test_expr> evaluates to a non-Boolean value, then the value is first cast to Boolean using the rules of the $boolean function.
Example
This example continues to use the claim-batch input shown above. The expression evaluates the fourth claim line's allowedAmount from the full document.
Expression:
claimLines[3].allowedAmount < 100 ? "low" : "standard"
Result:
"low"
Array constructor
Square brackets can be used to construct a new array. This is the normal JSON syntax for arrays, and it works in FUME because JSONata is a superset of JSON.
Use an array constructor when you want to return a fixed-size list of values. Array items can be any valid expression, and the output array will contain the evaluation results of the corresponding expressions, in the same order.
Note: Array items that evaluate to undefined are omitted from the result array.
Example: Build a new array from expressions
Input
{
"claimId": "clm-9001",
"lineCount": 2,
"allowed": [110, 180]
}
Expression
[claimId, lineCount, allowed[0]]
Result
[
"clm-9001",
2,
110
]
Async note
Array construction is a basic language feature, but also a concurrency helper. Parallel execution of array expression is possible when the entries contain async expressions.
For example, [$wait(1000), $wait(1000), $wait(1000)] finishes in about one second rather than three because the three waits can start together. See Parallelism And Async Evaluation for the full model, and browse related helpers in Async And Concurrency.
Object constructor
Curly braces can be used to construct a new object. Each entry is written as key: value. Keys may be string literals (quoted) or expressions that evaluate to strings. Values may be any expression.
Object constructors can be used either to build one object per selected item or to group a sequence into one combined object, depending on where the constructor appears in the expression.
Example: Build one object per input item
Input
{
"contacts": [
{ "kind": "home", "value": "555-0101" },
{ "kind": "work", "value": "555-0201" },
{ "kind": "work", "value": "555-0202" }
]
}
Expression
contacts.{kind: value}
Result
[
{ "home": "555-0101" },
{ "work": "555-0201" },
{ "work": "555-0202" }
]
Because the constructor follows the dot-map stage, each contact builds its own object.
Example: Group many items into one object
Input
{
"contacts": [
{ "kind": "home", "value": "555-0101" },
{ "kind": "work", "value": "555-0201" },
{ "kind": "work", "value": "555-0202" }
]
}
Expression
contacts{kind: value}
Result
{
"home": "555-0101",
"work": ["555-0201", "555-0202"]
}
Because the constructor follows the whole selected sequence directly, FUME combines the generated key/value pairs into one object. Repeated keys are grouped into arrays. This grouped form is also the basis of the reduce-style { ... } stage documented in Path Operators.
JSON literals
Any valid JSON document is also a valid FUME expression. That means you can write strings, numbers, booleans, null, arrays, and objects directly in an expression, then replace selected parts with dynamic expressions.
This makes JSON syntax useful as a template for the output you want to build.
Example: Use JSON syntax as an output template
Input
{
"claimId": "clm-9001",
"allowedAmount": 180
}
Expression
{
"id": claimId,
"allowedAmount": allowedAmount,
"status": "ready",
"highAllowedAmount": allowedAmount >= 150,
"notes": null
}
Result
{
"id": "clm-9001",
"allowedAmount": 180,
"status": "ready",
"highAllowedAmount": true,
"notes": null
}
:= (Variable binding)
The variable binding operator is used to bind the value of the RHS to the variable name defined on the LHS. The variable binding is scoped to the current block and any nested blocks. It is an error if the LHS is not a $ followed by a valid variable name.
Examples
$five := 5$square := function($n) { $n * $n }
~> (Chain)
The function chaining operator is used in the situations where multiple nested functions need to be applied to a value, while making it easy to read. The value on the LHS is evaluated, then passed into the function on the RHS as its first argument. If the function has any other arguments, then these are passed to the function in parenthesis as usual. It is an error if the RHS is not a function, or an expression that evaluates to a function.
Examples
Input
This example uses the full claim-batch example input. The next two chain examples read either claimId or claimLines from that document before passing the value into chained functions.
Example input
{
"claimId": "clm-9001",
"memberId": "mbr-3001",
"claimLines": [
{
"lineNumber": 1,
"serviceDisplay": "office visit",
"allowedAmount": 110,
"modifiers": [
"MOD-A"
],
"units": 1,
"unitPrice": 125
},
{
"lineNumber": 2,
"serviceDisplay": "imaging study",
"allowedAmount": 300,
"modifiers": [
"MOD-B",
"MOD-C"
],
"units": 1,
"unitPrice": 350
},
{
"lineNumber": 3,
"serviceDisplay": "counseling",
"allowedAmount": 150,
"modifiers": [],
"units": 3,
"unitPrice": 60
},
{
"lineNumber": 4,
"serviceDisplay": "lab panel",
"allowedAmount": 70,
"modifiers": [
"MOD-A"
],
"units": 2,
"unitPrice": 40
}
]
}
Expression:
claimId ~> $substringAfter("clm-") ~> $number()
Result:
9001
This example continues to use the claim-batch input shown above. The expression calculates each claim line total from the full document and then sums the resulting sequence.
Expression:
claimLines.(unitPrice * $number(units)) ~> $sum()
Result:
735
This operator can also be used in a more abstract form to define new functions based on a combination of existing functions. In this form, there is no value passed in on the LHS of the first function in the chain.
For example, the expression
(
$uppertrim := $trim ~> $uppercase;
$uppertrim(" Hello World ")
)
=> "HELLO WORLD"
creates a new function $uppertrim that performs $trim followed by $uppercase.