Skip to main content

$parseInteger

$parseInteger(string?, picture) -> number
Compact type signature<s-s:n>

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

Source: JSONata

Documentation

Parses the contents of the string parameter to an integer (as a JSON number) using the format specified by the picture string. The picture string parameter has the same format as $formatInteger. Although the XPath specification does not have an equivalent function for parsing integers, this capability has been added to JSONata.

Examples

Basic usage

  • $parseInteger("twelve thousand, four hundred and seventy-six", 'w') => 12476
  • $parseInteger('12,345,678', '#,##0') => 12345678

Parse an integer from an identifier

Input

This example uses the patient-summary example input. The expression reads identifiers.memberId, extracts its numeric suffix, and parses it.

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

$parseInteger($substringAfter(identifiers.memberId, "-"), "0")

Result

3001