# Dictionary to Pydataset

**URL:** <https://forum.inductiveautomation.com/t/dictionary-to-pydataset/11758>\
**Category:** Ignition\
**Created:** [May 31, 2016, 11:51pm UTC](https://forum.inductiveautomation.com/t/dictionary-to-pydataset/11758 "2016-05-31T23:51:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ks0](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ks0/32/6813_2.png) [@ks0](https://forum.inductiveautomation.com/u/ks0)\
**Post date:** [May 31, 2016, 11:51pm UTC](https://forum.inductiveautomation.com/t/dictionary-to-pydataset/11758/1 "2016-05-31T23:51:13Z")

</div>

Is there a nice function to convert a python dictionary into a pydataset?

Cheers,  
Keiran

---

<div class="post-metadata">

**Author:** ![nmudge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nmudge/32/3394_2.png) [@nmudge](https://forum.inductiveautomation.com/u/nmudge)\
**Post date:** [May 31, 2016, 11:58pm UTC](https://forum.inductiveautomation.com/t/dictionary-to-pydataset/11758/2 "2016-05-31T23:58:52Z")

</div>

What is the structure of the dictionary?

---

<div class="post-metadata">

**Author:** ![ks0](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ks0/32/6813_2.png) [@ks0](https://forum.inductiveautomation.com/u/ks0)\
**Post date:** [June 1, 2016, 12:11am UTC](https://forum.inductiveautomation.com/t/dictionary-to-pydataset/11758/3 "2016-06-01T00:11:08Z")

</div>

So for example, I want to take this “objects” data, and put it in an “objects” dataset tag:

```auto
dict = { "objects" : [{ "id" : 123, "value" : 456789}, { "id" : 456, "value" : 789123}] }
```

And then…

[code]pds = _convert dict here_

dataset = system.dataset.toDataSet(pds)

system.tag.write(“ThisIsATag.value”, dataset)[/code]

---

<div class="post-metadata">

**Author:** ![nmudge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nmudge/32/3394_2.png) [@nmudge](https://forum.inductiveautomation.com/u/nmudge)\
**Post date:** [June 1, 2016, 12:25am UTC](https://forum.inductiveautomation.com/t/dictionary-to-pydataset/11758/4 "2016-06-01T00:25:44Z")

</div>

Okay, here’s a function that works and an example of using it:[code]def dictToDataset(dictValue):  
data = []   
columns = dictValue[“objects”][0].keys()  
for obj in dictValue[“objects”]:  
row = []  
for column in columns:  
row.append(obj[column])  
data.append(row)  
return system.dataset.toDataSet(columns,data)

dict = { “objects” : [{ “id” : 123, “value” : 456789}, { “id” : 456, “value” : 789123}] }

system.tag.write(“ThisIsATag.value”, dictToDataset(dict))[/code]Best,

---

<div class="post-metadata">

**Author:** ![ks0](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ks0/32/6813_2.png) [@ks0](https://forum.inductiveautomation.com/u/ks0)\
**Post date:** [June 1, 2016, 12:29am UTC](https://forum.inductiveautomation.com/t/dictionary-to-pydataset/11758/5 "2016-06-01T00:29:38Z")

</div>

Nick, that is awesome! Your help is much appreciated!

Cheers,  
Keiran
