This article demonstrates the easy conversion of JSON data into a raw CSV file using the JSON to CSV app developed by Quickwork.
What you'll need:
Skill level: Intermediate
Time required: 6 minutes
- A sample JSON data
- Skills to specify JSON data in its syntactical format
- JSON to CSV as an action
- Scheduler by Quickwork as a trigger--for triggering the journey
Why is CSV data important
CSV files are plain text files and are easier for a website developer to create. Since they're plain text, they're easier to import into a spreadsheet or any other storage database, regardless of the specific software you're using. It is always beneficial to better organize large amounts of data.
You can pass two types of JSON data to get converted into CSV:
- An object of JSON data
- An array of objects containing JSON data
Rules for specifying the JSON data:
- It should be within the box bracket
{...}
. - The last curly bracket
}
of the last JSON object should not have a comma,
. - The key-value pairs should be enclosed within double quotes
""
.
Violation of any of the above rules will throw an error as Bad request
.
Configuring the trigger
- In the Event section, choose the Scheduler by Quickwork app from the drop-down menu in the Apps field.
- Select the trigger event, New scheduled event, from the drop-down menu in the Triggers field.
- Set the Interval for One day as we need to fetch the breaking news only once a day on a daily basis.
- Set the date and time of your choice in the Start at field and keep the Custom payload field empty:
Passing the JSON object to be converted
- Under the Steps section, click on the Simple Action button and choose the JSON to CSV app from the drop-down menu in the Apps field.
- Select the Convert JSON to CSV action from the drop-down menu in the Actions field.
- No authorization is required as this is a self-created app of Quickwork.
- In the JSON data source field, select String or URL as a source of JSON depending on your requirement. Since here we are using a sample JSON object and hardcoding it, we have selected String.
- In the Output field type field, select the CSV output as URL if you need the output in the format of a CSV file. You can also select string optionally if you do not need the output in a file. In that case, you can simply add a logger and record the output or use the output obtained directly in the form of a data pill in further actions whenever required.
- In the JSON data field, specify the JSON you want to convert:
[
{
"userId": 123,
"age": 25,
"name": "Mr. Andrew Hall",
"designation": "Software Engineer"
},
{
"userId": 456,
"age": 27,
"name": "Mr. Simpson Cliff",
"designation": "Technical Writer"
},
{
"userId": 789,
"age": 40,
"name": "Ms. Phelope Shaw",
"designation": "Graphics Designer"
},
{
"userId": 290,
"age": 35,
"name": "Mr.Scott Styris",
"designation": "Marketing Manager"
}
]
Note: You can generate the sample JSON data from JSONPlacholder while testing this app. Ensure to remove the comma from the last curly bracket of the JSON object, else you'll face an error. - In the Fields field, specify all the keys present in your JSON object in a comma-separated format. E.g.,
userId,age,name,designation
:
Executing the journey
Save all the changes in the journey and click the Save & Start button. You'll be taken to the History tab automatically. Click on the record that just got created. In the Steps section, click the action bar to expand. The Input block shows the inputs provided. The Output block will contain a URL to the generated CSV file:
Copy it and paste it into a web browser to view the CSV data:
Thus, your JSON data has been successfully converted to CSV format. Now you can use this data to store it in your legacy system or dump it in the database for future use.
Comments
0 comments
Please sign in to leave a comment.