# Convert a Table to JSON

### Overview

This procedure transforms a given table into its JSON representation. It accepts a table as input and outputs a JSON that represents the table's structure and content.

### Syntax

Below is a line-by-line overview of the automation syntax. Expand each line to learn more.

<details>

<summary><code>convert the table to a json</code></summary>

#### What does it do?

Instructs the system to convert the table to a JSON string.

#### Where does it go?

This phrase should be written on a **new line**.

#### Is it required?

✅ Yes — This phrase is **required**.

#### Does it require data?

✅ Yes — A reference to **the table** must be provided.

</details>

<details>

<summary><code>the datetime format is "your-format"</code></summary>

#### What does it do?

Defines the format used to represent datetime values when converting table data to JSON.

#### Where does it go?

Indented under `convert the table to a json`.

#### Is it required?

❌ No — This phrase is **optional**.

#### Does it require data?

✅ Yes — Replace **your-format** with your desired datetime format.

#### Example

```
the datetime format is "%Y-%d-%m"
```

</details>

### Examples

#### 1. Convert a Sample Table to JSON

{% tabs %}
{% tab title="Automation" %}

```
create a sample table
convert the table to a json
```

{% endtab %}

{% tab title="Results" %}
**the json**

* Address: 123 east street City: San Francisco Name: john Number: + 1 (415) 691 9426
* Address: 321 west street City: San Jose Name: joe Number: + 1 (415) 691 1234
* Address: 213 north street City: San Francisco Name: jack Number: + 1 (415) 691 4595
  {% endtab %}
  {% endtabs %}

#### 2. Convert a Table to JSON with Date & Time Data

Consider the following table that is stored in a `.xlsx` file:

| Vegetable | Harvest Date | Harvest Time | Quantity (kg) |
| --------- | ------------ | ------------ | ------------- |
| Carrot    | 2025-01-15   | 14:30:00     | 150           |
| Broccoli  | 2025-03-20   | 09:00:00     | 85            |

{% tabs %}
{% tab title="Automation" %}

```
open the table at the file
convert the table to a json
    the datetime format is "%m-%d-%Y"
```

{% endtab %}

{% tab title="Results" %}
**the json**

* Harvest Date: 01-15-2025 Harvest Time: '14:30:00' Quantity (kg): 150 Vegetable: Carrot
* Harvest Date: 03-20-2025 Harvest Time: '09:00:00' Quantity (kg): 85 Vegetable: Broccoli
  {% endtab %}
  {% endtabs %}

### Details

The table below lists common datetime codes that can be combined to specify a format string.

Each directive represents a specific component of a date or time, such as year, month, day, etc.

| Directive | Description                 | Example                  |
| --------- | --------------------------- | ------------------------ |
| `%Y`      | 4-digit year                | 2025                     |
| `%y`      | 2-digit year                | 25                       |
| `%m`      | Month (01-12)               | 06                       |
| `%B`      | Full month name             | June                     |
| `%b`      | Abbreviated month name      | Jun                      |
| `%d`      | Day (01-31)                 | 18                       |
| `%H`      | Hour (24-hour, 00-23)       | 14                       |
| `%I`      | Hour (12-hour, 01-12)       | 02                       |
| `%p`      | AM/PM                       | PM                       |
| `%M`      | Minute (00-59)              | 30                       |
| `%S`      | Second (00-59)              | 45                       |
| `%f`      | Microsecond (000000-999999) | 000123                   |
| `%z`      | UTC offset (+HHMM)          | +0000                    |
| `%Z`      | Timezone name               | UTC                      |
| `%j`      | Day of year (001-366)       | 169                      |
| `%U`      | Week number (Sun first day) | 25                       |
| `%W`      | Week number (Mon first day) | 25                       |
| `%c`      | Locale date & time          | Tue Jun 18 14:30:00 2025 |
| `%x`      | Locale date                 | 06/18/25                 |
| `%X`      | Locale time                 | 14:30:00                 |
