# XML/JSON File Destination

Astera's *XML/JSON File Destination* object provides the functionality to write data to an XML or JSON file when the data is in a hierarchical format.

{% embed url="<https://youtu.be/mWdoPPFjO0c>" %}

## **Use Case**

In order to understand how to write to an *XML/JSON File Destination* object, we will take the help of a use-case where we will convert flat datasets to a hierarchical set, and then write the transformed data to an XML file.

The *Customers* and *Orders* data from database tables will be used as source objects. We will then join them using the *TreeJoin* Transformation to create a hierarchical dataset.

Learn more about how the[ *Treejoin Transformation* ](https://documentation.astera.com/v/astera-data-stack-v8/dataflows/transformations/tree-join-transformation)works in Astera.

![](https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2FNrBNggPSreleN2ff4VG9%2F0.png?alt=media)

## **Configuring the XML/JSON File Destination Object**

1. To get an *XML/JSON File Destination* object from the Toolbox, go to *Toolbox > Destinations > XML/JSON File Destination* and drag and drop it onto the designer. If you are unable to see the Toolbox, go to *View > Toolbox* or press Ctrl + Alt + X.

![](https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2FySiyMVTf0K2HO5r9srsS%2F1.png?alt=media)

![](https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2Fj9N7rRZvgrlWJvQZNtai%2F2.png?alt=media)

The dragged destination object is empty right now. This is because the object has not been configured yet.

{% hint style="info" %}
**Note:** In this case we will be using the use case discussed earlier, taking the *Treejoin* as the source for data to write to the *XML/JSON File Destination.*
{% endhint %}

![](https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2FoKLzgLZu6iRjcSQfzSUt%2F3.png?alt=media)

## **Creating a Schema File**

A schema file is needed to write data to an *XML/JSON File Destination*. To create the schema file, right-click on the source object (*Treejoin* transformation in this case), and a context menu will appear. Select the option *Generate XML Schema for layout*.

![](https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2FlSqSjs1pwFUmDlPBBwOw%2F4.png?alt=media)

* A new dialog box will open where you will be asked to save the XML schema file. Give the *File Name* and file path for the schema file and click *Save*.

![](https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2FeY4N2IXZYuRnMtr69WoO%2F5.png?alt=media)

* The schema file has been created in the specified location. To view this file, go to the file location and open the file in Astera.

The opened file would look like the one below:

![](https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2FUAk1T18Wrfl3KuWOrBgK%2F6.png?alt=media)

## **File Path**

1. To configure the *XML/JSON File Destination* object, right-click on its header and select *Properties* from the context menu.

![](https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2FqxhrAHejuQoxBCtwcDsf%2F7.png?alt=media)

2. A window, *Destination XML File*, will open. Here we will specify the file locations; *File Path* and *Schema File* for the *XmlJsonDest* object

![](https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2FJWmV5OnPuSOFpw0P7bWr%2F8.png?alt=media)

* The destination file will now be saved in the provided file location. Click *OK*, and map the destination object to the source object before further configuration.

![](https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2FF9CVbzpYIn9i7cZH7q1q%2F9.png?alt=media)

* The *XmlJsonDest* object will now have the layout of the source object (*Treejoin* Transformation in this case).

![](https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2FfoPeMoDUGJMD6yerBK7y%2F10.png?alt=media)

## **Mapping**

1. To map the source object to the destination object, the following ways of mapping can be used:

i. By dragging and dropping the parent node of the source object (*TreeJoin* node in the *TreeJoin* table) onto the child node of the destination object (*TreeJoin* node in the *XmlJsonDest* object) for automatic mapping.

![](https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2FwdHjBCVXIrzduad0uZCR%2F11.png?alt=media)

ii. By manually mapping the source parent node (*TreeJoin* in the *TreeJoin* table) by dragging it to the respective destination child node (*TreeJoin* in the *XmlJsonDest* object).

![](https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2F9EyrMQVFKjOwfM4bXoZd%2F12.png?alt=media)

* The fields are now mapped.

![](https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2FANFUdmhgVkYlBkTcjSqW%2F13.png?alt=media)

## **Properties**

Once the file locations have been specified and the mappings have been done, further properties can be defined.

***XML Layout***

* The next window after the *Destination XML File* window is the *XML Layout* window.

![](https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2FI0v2rbPY9hg9100rzZDT%2F14.png?alt=media)

* This window shows the XML layout for the *XmlJsonDest* object. The collection nodes for the object can be seen in this window with their fields.

***Config Parameters***

* Click *Next*, and a window, *Config Parameters*, will open, which will allow us to further configure and define parameters for the *XML/JSON Destination* object.

Parameters can provide easier deployment of flows by eliminating hardcoded values and provide an easier way of changing multiple configurations with a simple value change.

{% hint style="info" %}
**Note**: Parameters left blank will use their default values assigned on the properties page.
{% endhint %}

![](https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2FzOcOujJeFQ7WB7fLRYvJ%2F15.png?alt=media)

***General Options***

* Click *Next*, and a new window, *General Options,* will open. On this window:
  * *Comments* can be added.
  * *General Options* are given, which relate to processing of records in the destination file.
    * *Clear Incoming Record Messages:* For any messages coming in from objects preceding the current object to be cleared.
    * *Do Not Process Records With Errors:* Will not let erroneous records to proceed further for the output.
    * *Do Not Overwrite Default Values with Nulls:* Ensure that values are not overwritten with null values in the output.

![](https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2FCzxhGiytpw4IDzTQ2dw4%2F16.png?alt=media)

* Click *OK*.

![](https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2FAWOomGGKWcY2LtsDJkqd%2F17.png?alt=media)

The *XmlJsonDest* object has been successfully configured and the destination file can now be created by running the dataflow.
