# XML JSON Parser

An *XML/JSON Parser* reads and processes a single text stream of hierarchical data and give elements as parsed output in XML/JSON format.

**Sample Use-Case**

In this case, we are using an [*Excel Workbook Source*](https://documentation.astera.com/v/astera-data-stack-v8/dataflows/sources/excel-workbook-source).

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

The source file contains details of customers’ orders.

To preview data, right-click on the source object’s header and select *Preview Output* from the context menu.

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

A *Data Preview* window will open, displaying the source data.

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

Observe that it is difficult to decipher fields and elements when the data is in a text stream. To make sense of this data, it needs to be structured in a proper format, with fields and collection regions clearly identified.

To parse this source data, we will use *XML/JSON Parser* in Astera.

## **Using XML/JSON Parser**

1. To get the *XML/JSON Parser* object, go to *Toolbox > Text Processors > Parser* and drag-and-drop the object onto the designer.

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

You can see that the dragged object contains a *Text* field.

2. Map the *Text* field in the *Customer\_Orders* object to the *Text* field in the *XMLJSONParser* object.

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

3. Right-click on the object’s header and select *Properties*.

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

A configuration window will open, as shown below.

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

4. Provide the XML schema path. Astera will parse the text file based on the structure defined in the schema file.

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

Click *Next*. This is the *Layout Builder* screen where the final layout of the incoming fields and the collection regions can be seen.

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

Click *OK*. The data stream is parsed into regions and fields which can be seen on the *XMLJSON Parser* object.

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

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

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

A *Data Preview* window will open. Expand the nodes, and you will see the parsed output for each record.

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

To store this parsed output, write it to a destination file.

6. Right-click on the *Customer\_Orders* node under the *XMLJSON Parser* object, and go to *Write to > Database Table Destination*. A *Database Table Destination* object is added to the dataflow designer with all fields auto-mapped to it.

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

7. Configure settings for the[ *Database Table Destination*](https://documentation.astera.com/v/astera-data-stack-v8/dataflows/destinations/database-table-destination) object.
8. Click on the *Start Dataflow* button placed in the toolbar at the top to create the destination file.

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

A database table will be successfully created, with parsed output in XML format.
