# Formatter

Formatter is used to format the given data. It is designed to handle the conversion of data between different formats, such as CSV, string, XML, and JSON. Also, the formatter provides the ability to generate the timestamp and convert between timezones. This tool facilitates the transformation of data to and from the JSON format, offering seamless interoperability.

### Options

* ***Data (to be formatted)*** - the data that will be formatted according to the selected `Formatter Action`
* ***Formatter Action*** - action to be applied to the above data
  * [JSON to STRING](#json-to-string)
  * [STRING to JSON](#string-to-json)
  * [XML to JSON](#xml-to-json)
  * [JSON to CSV](#json-to-csv)
  * [CSV to JSON](#csv-to-json)
  * [Generate Timestamp](#generate-timestamp)
  * [Convert Timezone](#convert-timezone)
* ***Delimiter*** - Separator used in CSV. Applicable to `JSON to CSV` and `CSV to JSON` options. `,` is the default value.&#x20;
* ***From Time Zone*** - Applicable only to [Convert Timezone](#convert-timezone)
* ***To Time Zone*** - Applicable only to [Convert Timezone](#convert-timezone)
* ***Output Format*** - Applicable only to [Convert Timezone](#convert-timezone)

### Formatter Actions

#### JSON to STRING

Converts JSON to Stringified JSON.

```json
Data:
{"name": "John Doe",   "age": 30,   "city": "Exampleville" }

Output:
"{\"name\": \"John Doe\", \"age\": 30, \"city\": \"Exampleville\" }"
```

<figure><img src="/files/hGMcuPiTjGRZf16My5QR" alt=""><figcaption></figcaption></figure>

#### STRING to JSON

Converts stringified JSON to JSON.

```json
Data:
"{\"name\": \"John Doe\", \"age\": 30, \"city\": \"Exampleville\"}"

Output:
{"name": "John Doe", "age": 30, "city": "Exampleville"
```

<figure><img src="/files/rWsuOMdqNSUMIppGkT8s" alt=""><figcaption></figcaption></figure>

#### XML to JSON

Converts XML to JSON format

```xml
Data:
<person><name>John Doe</name><age>30</age><city>Exampleville</city></person>

Output:
{'person': {'name': 'John Doe', 'age': '30', 'city': 'Exampleville'}}
```

<figure><img src="/files/Zpgq22f2vHbOU5a22g3f" alt=""><figcaption></figcaption></figure>

#### JSON to CSV

Converts JSON to CSV format

```json
Data:
[
  {
    "name": "John Doe",
    "age": 30,
    "email": "john@example.com",
     "street": "123 Main St",
      "city": "New York",
      "zip": "10001"
  },
  {
    "name": "Jane Smith",
    "age": 25,
    "email": "jane@example.com",
      "street": "456 Elm St",
      "city": "Los Angeles",
      "zip": "90001"
  }
]

Output:
b'name,age,email,street,city,zip\nJohn Doe,30,john@example.com,123 Main St,New York,10001\nJane Smith,25,jane@example.com,456 Elm St,Los Angeles,90001\n'
```

<figure><img src="/files/LTJFFVpiBFUubc1BJQ5f" alt=""><figcaption></figcaption></figure>

#### CSV to JSON

Converts CSV to JSON format. New lines can be entered as a new line or as `\n`

```json
Data 1:
"name,age,email,street,city,zip
John Doe,30,john@example.com,123 Main St,New York,10001
Jane Smith,25,jane@example.com,456 Elm St,Los Angeles,90001"

Data 2:
"name,age,email,street,city,zip\nJohn Doe,30,john@example.com,123 Main St,New York,10001\nJane Smith,25,jane@example.com,456 Elm St,Los Angeles,90001\n"

Output:
[{'name': 'John Doe', 'age': '30', 'email': 'john@example.com', 'street': '123 Main St', 'city': 'New York', 'zip': '10001'}, {'name': 'Jane Smith', 'age': '25', 'email': 'jane@example.com', 'street': '456 Elm St', 'city': 'Los Angeles', 'zip': '90001'}]
```

<figure><img src="/files/g14mnhcAADnYxLYwefJC" alt=""><figcaption></figcaption></figure>

#### Generate Timestamp

Option to generate a timestamp from a given date time.&#x20;

**Usage Example**

Data (to be formatted): Enter the date and time from which you want to generate a timestamp.

From Time Zone: Select the time zone of the input date and time you want to convert the timestamp to.

<figure><img src="/files/ugy2PrnriPF0CDIdaGSG" alt=""><figcaption></figcaption></figure>

Refer [Allowed Datetime Formats](#allowed-datetime-formats) for the datetime structure format

#### Convert Timezone

Option to convert date and time from one timezone to another. This is particularly useful when you need to work with date and time data originating from different locations around the world.

**Usage Example**

Data (to be formatted): Enter the date and time you want to convert

For date-time input: Provide your date-time input.

From Time Zone: Select the original time zone of the input date and time.

To Time Zone: Choose the target time zone to which you want to convert the input date and time.

Output Date Format: Specify the desired format for the converted date and time. You can use the format codes described below to define the format as per your requirements.

<figure><img src="/files/G8OzOOsu462TYNeI8NtT" alt=""><figcaption></figcaption></figure>

Refer [Allowed Datetime Formats](#allowed-datetime-formats) for the datetime structure format

#### Output

The "Convert Timezone" option will provide the date and time converted to the specified target time zone, formatted according to your specified output date format.

### Allowed DateTime Formats

#### The following formats are supported:

| Format | Value    | Description                                |
| ------ | -------- | ------------------------------------------ |
| %d     | 27       | numerical representation of day            |
| %a     | Sat      | short alphabetical representation of day   |
| %A     | Saturday | alphabetical representation of day         |
| %m     | 01       | numerical representation of month          |
| %b     | Jan      | short alphabetical representation of month |
| %B     | January  | alphabetical representation of month       |
| %y     | 18       | short representation of year               |
| %Y     | 2018     | numerical representation of year           |
| %H     | 10       | hour                                       |
| %M     | 30       | minute                                     |
| %f     | 012345   | microseconds                               |
| %p     | AM       | meridiem                                   |
| %z     | +0530    | timezone offset                            |

#### Examples for reference :

| Input                           | Format                   |
| ------------------------------- | ------------------------ |
| 2021-05-27 01:30:00 PM          | %Y-%m-%d %H:%M:%S %p     |
| 2021-05-12T09:46:47-0400        | %Y-%m-%dT%H:%M:%S%z      |
| Sat, 27 Jan 2018 17:16:55 +0000 | %a, %d %b %Y %H:%M:%S %z |
| 2018-01-27T13:34:25.518993+0530 | %Y-%m-%dT%H:%M:%S.%f%z   |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.dckapintegrator.com/project-manager/workflows/actions/formatter.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
