# XML JSON Serializer

*XML/JSON Serializer* reads hierarchical data and converts it into a text stream. It is basically the conversion of data in a structured format to a single stream in a text-like format.

**Sample Use-Case**

In this case, we are using an [*XML/JSON File Source*](https://documentation.astera.com/astera-data-stack-v9/dataflows/sources/xml-json-file-source)*.*

![](https://3891069449-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F28dJIkGHacXhBlux3efx%2Fuploads%2FkkQZQ36MiXnNO0oLlY5b%2F0.jpeg?alt=media)

The *XML/JSON File Source* contains the hierarchical data of customers, their orders, and the order details.

Right-click on the *XML/JSON File Source* object’s header, and select the *Preview Output* to visualize the hierarchical data.

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

View the source data from the *Data Preview* window.

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

Now, to convert this hierarchical data into a single text stream, we will use the *XML/JSON Serializer* object.

**Using the XML/JSON Serializer**

1. Select the *XML/JSON Serializer* object from the Toolbox window and drag and drop it onto the dataflow designer.

![](https://3891069449-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F28dJIkGHacXhBlux3efx%2Fuploads%2FVeXqTrgMbvpSMCU8fo8T%2F3.gif?alt=media)

2. Right-click on the *XML/JSON Serializer* object’s header, and select *Properties* from the context menu.

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

A configuration window will open, as shown below.

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

3. Provide the *File Path* for the [*XML Schema*](https://documentation.astera.com/astera-data-stack-v9/sources/xml-json-file-source#configuring-the-xml-json-file-source-object) i.e., the structure or layout of the XML File.

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

* Check the *JSON Format* option if your file is a JSON.

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

Click *Next.* This is the *Config Parameters* window, which allows us to configure and define certain parameters for the *XML Serializer Source* file.

* The use of parameters eliminates the process of inserting hardcoded values and provides simplification in the deployment of flows. If the parameters are left empty, the default values defined in the *Properties* window are assigned for use.

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

Now, click *OK*, to proceed further.

4. Map the fields of the *XML/JSON File Source* object onto the *XML/JSON Serializer* object’s fields.

![](https://3891069449-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F28dJIkGHacXhBlux3efx%2Fuploads%2FgLxdtT7UN0rXsv3qF7SJ%2F9.gif?alt=media)

5. Right-click on the object’s header, and select *Preview Output*.

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

You can view the data through the *Data Preview* window.

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

Hover over the *Text* field and you will see the *Serialized* output i.e., stream of text for each hierarchical record of the XML/JSON file.

To store the *Serialized Output,* we must write it to a destination file.

### Writing to a Destination

1. Right-click on the *XmlJsonSerializer,* select *Write To* and select your desired destination object. A destination object is created on the dataflow designer with the *Text* field auto-mapped.

![](https://3891069449-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F28dJIkGHacXhBlux3efx%2Fuploads%2FV7MFM8ZVGjxSnbhLmxKt%2F12.gif?alt=media)

Here, we have used an [*Excel Workbook Destination* ](https://documentation.astera.com/astera-data-stack-v9/dataflows/destinations/excel-workbook-destination)object.

2. Right-click on the destination object’s header and provide the *File Path* for the destination file. Select the relevant options and click *OK.*

![](https://3891069449-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F28dJIkGHacXhBlux3efx%2Fuploads%2FPrjD23Pji0aEFoMNCCwD%2F13.jpeg?alt=media)

By running this dataflow, you can now create an Excel file containing the serialized XML output.

![](https://3891069449-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F28dJIkGHacXhBlux3efx%2Fuploads%2FgCKyV1z1JzjneXpMJxeq%2F14.jpeg?alt=media)

This is how an *XML Serializer* Object can be used to format hierarchical data into a single stream of text in Astera.
