# Data Types

Data can be sent to Documint in several different types. Below is a list of those types and how to use them in your templates.

### Strings

Strings are simply text data.&#x20;

#### Example

{% tabs %}
{% tab title="Template" %}
{{customer\_name}}
{% endtab %}

{% tab title="Data" %}

```
{
    customer_name: "Acme Co."
}
```

{% endtab %}

{% tab title="Result" %}
Acme Co.
{% endtab %}
{% endtabs %}

### Numbers

Numbers are integers or floating-point decimals.

#### Example

{% tabs %}
{% tab title="Template" %}
{{total\_amount}}
{% endtab %}

{% tab title="Data" %}

```
{
    total_amount: 149.99
}
```

{% endtab %}

{% tab title="Result" %}
149.99
{% endtab %}
{% endtabs %}

{% hint style="info" %}
You can format numbers using the `$number` format.&#x20;
{% endhint %}

### Booleans

Booleans are values that are either `true` or `false` . They can not contain any values other than these.

#### Example

{% tabs %}
{% tab title="Template" %}
{{is\_fragile}}
{% endtab %}

{% tab title="Data" %}

```
{
    "is_fragile": true
}
```

{% endtab %}

{% tab title="Result" %}
true
{% endtab %}
{% endtabs %}

### Objects

Objects are groups of key-value pairs.  Unlike strings, numbers, and booleans, objects have nested properties that you access using dot notation. For example, let's say that we have an object named `address` with 4 properties; `street1`, `city`, `state`, and `country` and we want to display the `street1` property we'll use the following token `{{ address.street1 }}`. If we were to use a token with the name of the object (eg. `{{ address }}`) this would result in `[object Object]`.

#### Example

{% tabs %}
{% tab title="Template" %}
{{address.street1}}
{% endtab %}

{% tab title="Template" %}

```
{
    "address": {
        "street1": "123 Main St.",
        "city": "New York",
        "state": "NY",
        "country": "United States"
    }
}
```

{% endtab %}

{% tab title="Result" %}
123 Main st.
{% endtab %}
{% endtabs %}

{% hint style="warning" %}
If a variable is set to the name of the object rather than a property of that object, it will render as `[object Object]`. For example, if the variable in the template in the example above was `{{ address }}` instead of `{{address.street1}}` this would render as `[object Object]` because the entire `address` object is trying to be rendered instead of a property (eg. `street1`) of that object.&#x20;
{% endhint %}

### Arrays

An array is a list of items. This can be a list of any other data type, including objects (an array of objects is called a collection) and other arrays. Arrays are what you will use to repeat/loop elements in your template.&#x20;

#### Example 1: Display a single item

{% tabs %}
{% tab title="Template" %}
{{movies\[0]}}

{{movies\[2]}}
{% endtab %}

{% tab title="Data" %}

```
{
    "movies": [
        "Cinderella",
        "Avatar",
        "Million Dollar Baby",
        "Toy Story"
    ]
}
```

{% endtab %}

{% tab title="Result" %}
Cinderella

Million Dollar Baby
{% endtab %}
{% endtabs %}

#### **Example 2: Display all items**

{% tabs %}
{% tab title="Template" %}
{{#each movies }}\
Movie: {{this}}\
{{/each}}
{% endtab %}

{% tab title="Data" %}

```
{
    "movies": [
        "Cinderella",
        "Avatar",
        "Million Dollar Baby",
        "Toy Story"
    ]
}
```

{% endtab %}

{% tab title="Result" %}
Movie: Cinderella\
Movie: Avatar\
Movie: Million Dollar Baby\
Movie: Toy Story
{% endtab %}
{% endtabs %}

{% hint style="info" %}
You can also repeat an element for each item in an array. To learn more check out [Repeating Elements](https://docs.documint.me/legacy-documentation/repeating-elements)
{% endhint %}

{% hint style="warning" %}
**`[object Object]` Error**

Similar to objects you cannot display the array itself. If you do, this will result in `[object Object]` being displayed. Unlike objects, arrays must be either looped over to display each item in the array or display a specific item in the array.
{% endhint %}

### Collections

A collection is an array of objects. Because it's an array, it must be looped over like arrays. Because the items of the array are objects you must display the properties of the object and not the object itself.

**Example:**

In this example, we have a list of order line items that we want to display as a table. To do this we will loop over each item in the list of line items using the `#each` function.&#x20;

{% hint style="info" %}
When looping over a list of objects, you can access the properties of that object directly since variables within a loop are within the context of the current item.
{% endhint %}

{% tabs %}
{% tab title="Template" %}
{{#each line\_items}}\
{{qty}} x {{name}} @ {{$number amount "$0,0.00"}} ea.\
{{/each}}&#x20;
{% endtab %}

{% tab title="Data" %}

```
{
    "line_items": [
        {
            "name": "Sample widget 1",
            "price": 50,
            "quantity": 2,
            "amount": 100
        },
        {
            "name": "Sample widget 2",
            "price": 1200,
            "quantity": 1,
            "amount": 1200
        },
        {
            "name": "Sample widget 3",
            "price": 10,
            "quantity": 50,
            "amount": 500
        }
    ]
}
```

{% endtab %}

{% tab title="Result" %}
2 x Sample widget 1 @ $100 ea.\
1 x Sample widget 2 @ $1,200 ea.\
50 x Sample widget 3 @ $10 ea.
{% endtab %}
{% endtabs %}

{% hint style="info" %}
We're using the `$number` formatter here to format the `amount` property value.&#x20;
{% endhint %}
