Dictionary to Pydataset

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

Cheers,
Keiran

What is the structure of the dictionary?

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

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]

1 Like

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,

1 Like

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

Cheers,
Keiran

1 Like