Skip to main content

$length

$length(string?) -> number
Compact type signature<s-:n>

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

Browse categories

Source: JSONata

Documentation

Returns the number of characters in the string str. An error is thrown if str is not a string.

Examples

Basic usage

  • $length("Hello World") => 11

Count characters in a display string

Input

This example uses the patient-summary example input. The expression reads name.display and counts its characters.

Example input

JSON
{
"patientId": "pat-0001",
"name": {
"given": "Avery",
"family": "Reed",
"display": "Avery Reed"
},
"birthDate": "1990-06-12",
"sex": "female",
"primaryCareTeam": {
"organization": "ExampleCare",
"facility": "ExampleCare Clinic",
"practitioner": {
"practitionerId": "prac-4001",
"display": "Jordan Kim"
}
},
"identifiers": {
"memberId": "mbr-3001",
"recordNumber": "rec-5001"
},
"tags": [
"demo",
"fictional"
],
"_xmlTagName": "patientSummary"
}

Expression

$length(name.display)

Result

10