$substring
$substring(string?, start, length?) -> stringCompact type signature
<s-nn?:s>If string is omitted, the current context value is used.
Source: JSONata
Documentation
Returns a string containing the characters in the first parameter str starting at position start (zero-offset). An error is thrown if str is not a string.
If length is specified, then the substring will contain maximum length characters.
If start is negative then it indicates the number of characters from the end of str. See substr for full definition.
Examples
Basic usage
$substring("Hello World", 3)=>"lo World"$substring("Hello World", 3, 5)=>"lo Wo"$substring("Hello World", -4)=>"orld"$substring("Hello World", -4, 2)=>"or"
Extract a year from a date string
Input
This example uses the eligibility example input. The expression reads effective.start and extracts the year portion.
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
$substring(effective.start, 0, 4)
Result
"2026"