String

In JSONata String Functions, you can concat two strings to display multiple data records in one row, or write numbers as strings, or select only a few characters from the whole string, for example, to display a person's initials.

String functions

The string functions include:

Configuration

Result
Expression

String concat expression

[email protected] & ' ' & @ctx.datasources.mydata.title

String length

=$length(@ctx.datasources.mydata.name)

Substring

=$substring(@ctx.datasources.mydata.name, 3, 5)

Substring before

=$substringBefore(@ctx.datasources.mydata.name, " ")

Substring after

=$substringAfter(@ctx.datasources.mydata.name, " ")

Upper case

=$uppercase(@ctx.datasources.mydata.name)

Lower case

=$lowercase(@ctx.datasources.mydata.name)

Evaluate PathsData

=$eval(@ctx.current.item.pathsData)

base64

"data:image/png;base64," & @ctx.datasources.mydata.data

String to number

($number(@ctx.datasources.tmra-graph.Total) >= 5) ($number(@ctx.datasources.tmra-graph.Total) < 8) ? true : false

Two-letter placeholder for avatar

=$uppercase($substring($substringBefore(@ctx.current.item.firstName, " "), 0, 1) & $substring($substringAfter(@ctx.current.item.lastName, " ") , 0, 1) )

Examples and code snippets

String expressions
String expressions

This example shows how you can use various string functions to return data.See the full code sample in GitHub.

expression.jigx
datasources:
  mydata: 
    type: datasource.static
    options:
      data:
        - name: Jane Stevens
          title: Doctor
          email: [email protected]
          number: 0.64734
          number2: 12
          color: blue
          time: '2021-11-07T15:07:54.972Z'

children:
  - type: component.entity
    options:
      children:
        - type: component.entity-field
          options:
            label: String concat expression
            value: [email protected] & ' ' & @ctx.datasources.mydata.title
        - type: component.entity-field
          options:
            label: String length
            value: =$length(@ctx.datasources.mydata.name)
        - type: component.entity-field
          options:
            label: Substring
            value: =$substring(@ctx.datasources.mydata.name, 3, 5)
        - type: component.entity-field
          options:
            label: Substring before
            value: =$substringBefore(@ctx.datasources.mydata.name, " ")
        - type: component.entity-field
          options:
            label: Substring after
            value: =$substringAfter(@ctx.datasources.mydata.name, " ")
        - type: component.entity-field
          options:
            label: Upper case
            value: =$uppercase(@ctx.datasources.mydata.name)
        - type: component.entity-field
          options:
            label: Lower case
            value: =$lowercase(@ctx.datasources.mydata.name)

Last updated

Was this helpful?