Help Desk

Submit a ticket My Tickets
Welcome
Login

How to use the CSV to JSON Command and iterate over the results?

The OneCloud JSON BizApp has many powerful features that include the following commands: 

  • Array to CSV
  • CSV to JSON
  • Object to CSV
  • Validate Schema

This article will explore configuring OneCloud to convert a CSV to JSON Array and subsequently iterate over the JSON.

Sample Data

COL1,COL2,COL3
AA1,AA2,AA3
BB1,BB2,BB3
CC1,CC2,CC3

Chain Overview

CSV to JSON Configuration

Command Output - LIst File Content

Command Configuration & Output - Find String Sample Iteration 

With the Find Command, search the file with each element in the iteration. In this case, we are iterating over the values in "COL1". Note: in this example Chain, the "Find" Command has been renamed to "Find String" to accurately represent what the operation is doing. 

Run the Chain and review each of the iterations of the "Find" Command. Notice that the "Find Pattern" alternates from "AA1" to "BB1" to "CC1".

As always, we welcome questions on this post or feel free to contact us at support@onecloud.io.

Learn More

> How do I loop over a JSON Response?

> What is a JSON Output Schema and how do I populate it? 


  • Can I convert a comma separated text variable to JSON?


    Thanks,

    Mike

  • Hi Mike - Yes you can. That is the capability that the CSV to JSON Command provides. 

  • Thanks, Let me clarify, I realize that is what the command does when a file is passed, but can I convert a text string to it or something else, or must I write the string to a file, and then pass that file into the JSON - CSV to JSON command?

  • I went ahead and created a file from the string and turned it into JSON and it worked. But when I tried to move those steps to a sub-chain so they can be reused and the main chain would look cleaner, I ran into an issue where the chain output that I created from the output of the CSV to JSON in the new sub-chain will not work in the parent as an iterator.


    Please advise

  • Hi Mike - If I understand you correctly, you would need to pass the JSON list (as a resource) back to the Chain where the iteration is occurring. As for your prior question, yes, only outputs that are of type file can be used with CSV to JSON. It is worth mentioning that you could also use Handlebars Render Text Template to create the JSON structure without creating a file in advance.  

Login to post a comment