# Convert Array of objects to Dataset for export to CSV

**URL:** <https://forum.inductiveautomation.com/t/convert-array-of-objects-to-dataset-for-export-to-csv/68483>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [January 11, 2023, 2:05pm UTC](https://forum.inductiveautomation.com/t/convert-array-of-objects-to-dataset-for-export-to-csv/68483 "2023-01-11T14:05:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alex\_Leech](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/alex_leech/32/39391_2.png) [@Alex\_Leech](https://forum.inductiveautomation.com/u/Alex_Leech)\
**Post date:** [January 11, 2023, 2:05pm UTC](https://forum.inductiveautomation.com/t/convert-array-of-objects-to-dataset-for-export-to-csv/68483/1 "2023-01-11T14:05:02Z")

</div>

Hi all!

I've got a table in perspective that I use an export function to spit out to CSV (code below).

This is great for dumping the whole dataset, but doesn't give me the current data view.  
I thought I could get around this by instead enabling and copying the 'Results' data set when a filter is applied. The problem I'm having with this 'hack', is I first need to convert this into a dataset to be able to export it.  
When using system.xxx.toDataset on the array, it gives me a 5X1 dataset where the objects are strings and not columns.

Can anyone please advise how I correctly convert this structure to a dataset? And/or if there's a better way of exporting the current table data view to CSV?

Thanks!  
Alex

```auto
# Get the table component to retrieve the dataset from
table = self.parent.parent.getChild("TableOfThings")
	
# Create a CSV from the dataset
csvData = system.dataset.toCSV(dataset = table.props.data, showHeaders = True, forExport = False)

# Prompt the browser to download the file
system.perspective.download(fileName, csvData)

```

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [January 11, 2023, 2:36pm UTC](https://forum.inductiveautomation.com/t/convert-array-of-objects-to-dataset-for-export-to-csv/68483/2 "2023-01-11T14:36:50Z")

</div>

> [@Alex\_Leech](#):
>
> The problem I'm having with this 'hack', is I first need to convert this into a dataset to be able to export it.

This is far from a hack, it's pretty much what it's for.

I'm guessing you're passing the wrong thing to `toDataset`, but without the code all we can do is guess.  
This should make a proper dataset:

```python
data = self.parent.parent.getChild("TableOfThings")
headers = data[0].keys()
rows = [row.values() for row in data]
ds = system.dataset.toDataSet(headers, rows)
return ds

```

edit : one more thing... Be aware that saving results may have a performance cost.  
I used to do this with alarm tables and whatnot. I stopped because of performance issues.  
Now, for csv exports, I actually fetch the filters configuration from the table itself, then apply them in a `queryStatus` or whatever the function is that corresponds to the concerned table.  
The export itself might take longer than before, because I'm doing a query just for it, but the loading of the table itself is much smoother, and exports are actually quite rare.
