Skip to main content

$stringify

$stringify(value?, prettify?) -> string
Compact type signature<x-b?:s>

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

Source: FUME

Documentation

Serializes a value with JSON serialization semantics and returns the resulting string.

Unlike $string(), this helper still applies JSON serialization to string inputs, so the returned value for a string includes JSON quotes. If prettify is true, the JSON output is indented. Functions serialize to an empty string, and undefined input returns undefined.

Examples

Serialize a string value as JSON text

Input

This example uses the patient-summary example input. The expression serializes the patient display name with JSON string semantics.

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

$stringify(name.display)

Result

"\"Avery Reed\""