Remove "" From UpdateRow changes

Hello,
I’m trying to use system.dataset.updateRow and I am running into a small problem.

updates = {"Number":'{"style":{"backgroundColor":"#FFFF00"},"value":"44"}'}
		newPen = system.dataset.updateRow(pyData,1,updates)
		pyData = newPen
		
		return pyData

The problem is that when I go to check this row in the designer number has the following value

  "Number": "{\"style\":{\"backgroundColor\":\"#FFFF00\"},\"value\":\"44\"}",

And I need to instead be

  "Number": {"style":{"backgroundColor":"#FFFF00"},"value":"44"}",

How could I format updates to not do this?

should be

updates = {"Number":{"style":{"backgroundColor":"#FFFF00"},"value":"44"}}

(remove the single-quotes)

Unfortunatly that makes the problem a bit worse, result:

  "Number": "{\u0027style\u0027: {\u0027backgroundColor\u0027: \u0027#FFFF00\u0027}, \u0027value\u0027: \u002743\u0027}",

It also doesn’t remove the first/last "

To put the problem another way, I need to change the Dictionary Key from a value to an object, then insert 2 things into it. The first being a the value, and the second being an object(style), then I need to insert the backgroundColor value into the style object.

After looking at some previous threads we’ve interacted on, I’m going to assume this is an attempt at inserting a style object into a dataset, which you’re then trying to apply to a table’s data.

First things first:
From the docs, system.dataset.updateRow(pyData,1,updates) can only be used to change values for existing columns, so if “style” isn’t already in the dataset, you can’t add it. In the same way, you’d be unable to add backgroundColor because it doesn’t already exist. Situations like yours expose the limitations of datasets dealing with datasets directly.

Solution:
Convert the dataset into a python object, make your changes, and then send along this new object (or convert it back into a dataset and then send it along).

Try:

my_data = system.dataset.toPyDataSet(pyData)
for i in range(len(my_data)):
    # perform some logic here
    my_data[i]["style"] = {"backgroundColor": "#FFFF00"}
# this would return the PyDataSet
return my_data 
# or
# this would return the modified data as a Dataset
# return system.dataset.toDataSet(my_data)

Morning @cmallonee,
I tried what you suggested and received the following error:
TypeError:‘com.undictuveautimation.ignition.common.script.builtin.DatasetUtilities$PyDataSet$PyRow’ object does not support item assignment
I played around with using a standard db instead of a pyDb as well which yielded a similar error message saying that it’s unsubscriptable.
Would there be any other way to try this?

Disclaimer: the upcoming solution is terrible, and we’re aware this area needs improvement specifically due to cases like this.

Instead of returning the query data with auto or dataset, change the Return Format dropdown to “json”, then use the following code as an example.

my_data = [row.toDict() for row in value]
for i in range(len(my_data)):
    # perform some logic here
    my_data[i]["style"] = {"backgroundColor": "#FFFF00"}
return my_data 

@cmallonee
Thanks for the quick reply.
I have been playing around with your solution for a little while now, but unfortunately in this implementation ignition attempts to create a new column “style” and this actually doesn’t apply the backgroundColor.
What I believe needs to be done is modify the JSON of each column in each row to apply the style.
This is what I have been trying to do but I have little experience with JSON and python so it’s taking me a while.

@cmallonee
Finally have a way to do it if you are interested
I basically created a new dataset and did the following

newDataset.append({"Order Timeline":{"value":pyData[row][1],"style":{"backgroundColor": rowColor}}