# Calculating Variables

You can use basic JavaScript scripts in `${...}` syntax to calculate variables.

For example, to format a timestamp in different ways. Digdag bundles [Moment.js](http://momentjs.com/) for time calculation.

```yaml
timezone: America/Los_Angeles

+format_session_time:
  echo>: '${moment(session_time).format("YYYY-MM-DD HH:mm:ss Z")}'
+format_in_utc:
  echo>: '${moment(session_time).utc().format("YYYY-MM-DD HH:mm:ss")}'
+format_tomorrow:
  echo>: '${moment(session_time).add(1, ''days'').format("LLL")}'
+get_execution_time:
  echo>: '${moment().format("YYYY-MM-DD HH:mm:ss Z")}'
```

## Storing Typed Values with ${json:...}

The result of a `${...}` placeholder is always stored as a string. For example, when `items` is the array `[10, 20]`, `${items}` stores the string `[10,20]`.

Use the `${json:...}` placeholder to store a typed value. The placeholder evaluates a single JavaScript expression and stores the result as its JSON type (string, number, object, array, boolean, or null). An undefined result is stored as null.

For example, the following task uses `${json:...}` to send a number and an array in the JSON body of an `http>` request.

```yaml
_export:
  count: 3
  items: [10, 20]

+task:
  http>: https://api.example.com/path
  method: POST
  content:
    count: ${json:count}
    items: ${json:items}
  content_format: json
```

This task sends the body `{"count":3,"items":[10,20]}`. With `${count}` and `${items}`, the task sends the body `{"count":"3","items":"[10,20]"}`.

The following rules apply to `${json:...}`.

- The placeholder must be the whole value. A value that embeds the placeholder in text, such as `count is ${json:count}`, results in a configuration error.
- Write the marker exactly as `${json:`. A spaced form, such as `${ json : count }`, is evaluated as a normal `${...}` placeholder and results in a syntax error.
- A file rendered by an operator during execution, such as a query file or an email body, is always text. `${json:...}` in such a file is not evaluated and remains as written.