Skip to main content
Announcements
Qlik Introduces a New Era of Visualization! READ ALL ABOUT IT
cancel
Showing results for 
Search instead for 
Did you mean: 
j_
Contributor
Contributor

Csv to json Dynamically

I have requirement to convert csv to json dynamically ...I have job where the csv file has to be converted to json to load through api ..The same requirement has to be done for different csv file ..So is there any way to create as joblet dynamically or through routine ?

Labels (5)
2 Replies
Anonymous
Not applicable

This is an almost impossible requirement. If you look at a CSV file, there is no default JSON structure that will best suit it. Which are parent objects? Which are child objects? Which are arrays? Now you could possibly come up with an optimal structure by analysing data sets. But how do you know that your optimal structure will match your API requirements?

 

You will need to define your CSV data, identify the JSON formats that your APIs support and then match the data to the API JSON structure. You can get your data to find the correct job to convert the data appropriately, but you will find it very hard to dynamically create JSON from a single job I'm afraid.

 

David_Beaty
Creator III
Creator III

I would say this was possible - with a bit of Java coding, IF your CSV file has a header row with the column names.

 

It'd be a 2 step process:

 

  1. Read just row 1 of the CSV to get the headers, Normalise and the Aggregate back into a List
  2. Read each row with tFileInputFullRow, and mkanually extract each comma delimited column and form you JSON object using the List created in step 1 and the full row

 

It's quite a bit of messing around, but it would work - it does allow you to extract it out fully into a generic routine where you can pass in things like the delimiter as well to allow it to process files with different delimiters