How can I create an XML or JSON file from a CSV file?

How can I create an XML or JSON file from a CSV file?

Every now and then questions like the following come up in our Forum:

How can I create a JSON or XML file from tabular data (e.g. from a CSV file)?

Today we want to answer this question and present it in the video tutorial at the end of the article.

Often this question is asked because you want to connect a system like ERP or Onlineshop via API and you receive the data as CSV or Excel file (XLSX). Then, for example, you want to make an HTTP request from each row in an Excel spreadsheet that contains the columns as a JSON payload and sends it to the target system. You can also find which add-ons and steps you need for this at the end of the article.

Preparation - downloading and reading the CSV file

The first step is to download a CSV file, read it as a spreadsheet, and then convert it.

To do this, the following flow is created:

1. Download CSV file 2. read CSV file as spreadsheet (parse) 3. create JSON

The goal now is to build a JSON structure from this tabular data. For this we use the TextHTMLWriter step. With this step you can - simply said - create text. This can be HTML, XML or JSON. The TextHTMLWriter step is placed after reading (parsing) the CSV file, so that this data can be accessed.

You can now insert the read CSV data as a sample script to create the JSON structure. **This is the most important step.

Create the JSON structure

Now you are almost there. The example script must now only be adapted so that the output corresponds to the target format, which one needs.

Conclusion

With this example you can implement almost any integration where JSON or XML needs to be generated. In combination with the API-Connector Tools Add-On you can use it to query and connect to any API if there is no suitable Add-On for a target system in Synesty, for example.

If you want to know in detail how the flow is built or how the whole thing works with an XML file, just have a look at our video tutorial.

Video Tutorial

In this Synesty tutorial you will learn about the possibility to directly create an XML or JSON file from tabular data like a CSV file. With the help of Synesty Studio you can realize any integration and connection where XML or JSON plays a role.

Das Video wird bei Klick von Youtube geladen und abgespielt. Dabei stellt Ihr Browser eine Verbindung zu den Youtube-Servern her. Es gelten die Datenschutzhinweise von Google / Youtube

Get there faster with our template

The above example is also available as a ready-to-use template, which you can install in your Synesty account (also test account).

To the template

Our whitepaper for Makers: No Code Integration & Automation

Related articles


Last updated February 3, 2020
Chat with us