How to format data with filters

Help Center

Data formatting is a crucial aspect of document generation, allowing you to present information in a way that meets your specific requirements. Whether it’s dates, numbers, or other data types, having control over their presentation adds a layer of precision and professionalism to your documents.

To leverage data formatting filters, you need to use the enhanced syntax. Without it enabled, the formatting filters won’t be applied during document generation.

1. Format Dates
2. Format Numbers
3. Convert to Uppercase
4. Convert to Lowercase
5. Trim Whitespaces

1. Format Dates

One of the powerful formatting filters available is the date formatter. It enables you to control how dates appear in your generated documents. Here’s the syntax you need to use in your template:

[source_date | date:'date_format']
  • The source_date value needs to be in the ISO 8601 format (an international standard for representing dates and times). For instance, a date specified as yyyy-MM-dd will work seamlessly with the date formatter.

  • The date_format represents the desired output format for the date, and is based on the Unicode Technical Standard

Let’s say you have a date in your data set like this:

[{
  "source_date": "2023-06-15"
}]

Using the date formatter in your template:

Date: [source_date | date:'dd-MM-yyyy']

The result will be:

Date: 15-06-2023

Here are a few other examples of formatting options:

Format Result Description
dd-MM-yyyy 15-06-2023 Basic Date Format
dd/MM/yyyy 15/06/2023 Basic Date Format with Slashes
yyyy-MM-dd HH:mm 2023-06-15 00:00 Format with Hours and Minutes
yyyy-MM-dd HH:mm:ss 2023-06-15 00:00:00 Format with Hours, Minutes and Seconds
eeee, yyyy-MM-dd Friday, 2023-06-15 Custom Format with Day of the Week
MMM yyyy Jun 2023 Short Month and Year

2. Format Numbers

Another useful formatting filter is the number formatter. It enables you to control how numbers appear in your generated documents. Here’s the syntax you need to use in your template:

[source_number | number:'digits_format':'locale']
  • The source_number can be either a number or a string representing a number.

  • The digits_format specifies the value’s decimal representation in the following format:
    {minIntegerDigits}.{minFractionDigits}-{maxFractionDigits}.
    The {minIntegerDigits} is optional, so it is possible to specify it only as {minFractionDigits}-{maxFractionDigits}, where:
    • minIntegerDigits is the minimum number of integer digits before the decimal point. A value with a smaller number of integer digits than this number will be left-padded with zeros (to the specified length) when formatted. Possible values are from 1 to 21. The default is 1.
    • minFractionDigits is the minimum number of digits after the decimal point. Possible values are from 0 to 20. The default is 0.
    • maxFractionDigits is the maximum number of digits after the decimal point. Possible values are from 0 to 20. The default is 3.
  • The locale will format the source value according to locale rules. It is an optional string parameter with a BCP 47 language tag. The default is en-US.

Let’s say you have a date in your data set like this:

[{
  "source_number": 3.14159265359
}]

Using the number formatter in your template:

ĺ…€ with 3 decimals: [source_number | number]
ĺ…€ with 2 decimals: [source_number | number:'1.0-2']

The result will be:

ĺ…€ with 3 decimals: 3.142
ĺ…€ with 2 decimals: 3.14

As you can see in the “Pi with 3 decimals” example above, if no additional parameters are provided to the number filter, the value is formatted using the default digits_format, which is 1.0-3, and the default locale, which is en-US.

Here are a few other examples of formatting options:

Format Result Description
2.0-2 03.14 At least 2 digits before the decimal point and up to 2 digits after the decimal point. Leading zeros are added if necessary.
2-2 3.14 No requirement for the number of digits before the decimal point, but exactly 2 digits after the decimal point.
4.0-2:en-US 0,003.14 At least 4 digits before the decimal point, up to 2 digits after the decimal point, and formatted according to the en-US locale, with a comma as the thousands separator and a period as the decimal point.
4.2-2:fr-FR 0 003,14 At least 4 digits before the decimal point, exactly 2 digits after the decimal point, and formatted according to the fr-FR locale, with a space as the thousands separator and a comma as the decimal point.
4.2-2:fr 0 003,14 At least 4 digits before the decimal point, exactly 2 digits after the decimal point, and formatted with French-style formatting, using a space as the thousands separator and a comma as the decimal point
2 3.14159265359 Incorrect format, the original value is displayed as it is, with no specific number formatting applied.

3. Convert to Uppercase

To convert a text to uppercase you need to use the following syntax in your template:

[source_text | upper]

For the following data set:

[{
  "source_text": "Hello"
}]

The result will be:

HELLO

4. Convert to Lowercase

To convert a text to lowercase you need to use the following syntax in your template:

[source_text | lower]

For the following data set:

[{
  "source_text": "Hello"
}]

The result will be:

hello

5. Trim Whitespaces

Whitespaces are space, tab, no-break space characters and line terminator characters. To removes whitespaces from both ends of a string you need to use the following syntax in your template:

[source_text | trim]

For the following data set:

[{
  "source_text": "   Hello   "
}]

The result will be:

Hello