Skip to main content

$substringBefore

$substringBefore(string?, substring) -> string
Compact type signature<s-s:s>

If string is omitted, the current context value is used.

Browse categories

Source: JSONata

Documentation

Returns the substring before the first occurrence of the character sequence chars in str. If str does not contain chars, then it returns str. An error is thrown if str and chars are not strings.

Examples

Basic usage

  • $substringBefore("Hello World", " ") => "Hello"

Get the prefix portion of a code

Input

This example uses the eligibility example input. The expression reads plan.planCode and takes the prefix before the dash.

Example input

JSON
{
"memberId": "mbr-3001",
"patientId": "pat-0001",
"plan": {
"planCode": "PLAN-100",
"planName": "ExampleCare Standard"
},
"active": true,
"effective": {
"start": "2026-01-01",
"end": "2026-12-31"
},
"copay": {
"visit": 25,
"urgentCare": 50
},
"deductibleRemaining": 300
}

Expression

$substringBefore(plan.planCode, "-")

Result

"PLAN"