Skip to main content

$string

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

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

Browse categories

Source: JSONata

Documentation

Casts the arg parameter to a string using the following casting rules

  • Strings are unchanged
  • Functions are converted to an empty string
  • Numeric infinity and NaN throw an error because they cannot be represented as a JSON number
  • All other values are converted to a JSON string using the JSON.stringify function

If prettify is true, then "prettified" JSON is produced. i.e One line per field and lines will be indented based on the field depth.

Examples

Basic usage

  • $string(5) => "5"
  • [1..5].$string() => ["1", "2", "3", "4", "5"]