Skip to main content

$encodeUrlComponent

$encodeUrlComponent(string?) -> string
Compact type signature<s-:s>

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

Source: JSONata

Documentation

Encodes a single URL component using encodeURIComponent() semantics.

Use this helper for query parameter values, path fragments, or other individual pieces of a URL. Undefined input returns undefined, and malformed URI input raises a FUME URI error.

Examples

Encode a display name for a query parameter

Input

This example uses the patient-summary example input. The expression encodes the patient display name as a URL-safe component.

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

$encodeUrlComponent(name.display)

Result

"Avery%20Reed"