$trim
$trim(string?) -> stringCompact type signature
<s-:s>If string is omitted, the current context value is used.
Source: JSONata
Documentation
Normalizes and trims all whitespace characters in str by applying the following steps:
- All tabs, carriage returns, and line feeds are replaced with spaces.
- Contiguous sequences of spaces are reduced to a single space.
- Trailing and leading spaces are removed.
An error is thrown if str is not a string.
Examples
Basic usage
$trim(" Hello \n World ")=>"Hello World"
Trim note whitespace
Input
This example uses the free-text-notes example input. The expression reads the first note and trims its surrounding whitespace.
Example input
JSON
[
" follow-up recommended in 2 weeks ",
"reports intermittent headache; DX-001 noted",
"plan PLAN-100: confirm eligibility for mbr-3001",
"lab LAB-1002 flagged as HIGH; repeat test",
"pat-0001: patient prefers morning appointments",
"normalize multiple spaces"
]
Expression
$trim($[0])
Result
"follow-up recommended in 2 weeks"