How to read Object Wrapper

I cant seem to find a way to read objectWrapper with python. Flow is → rowData.toDict() → adding one new property → sending it to modal into button value → pushing button sends value to message handler and here I have problem reading it

I got error - Error running Page/Dashboard@C/root.onMessageReceived(self, payload): TypeError: unicode indices must be integers

payload here

	<ObjectWrapper>: {u'Shift': u'1n', u'MachineId': u'PRU1', u'qualitySize': u'13 - 0', u'Datum': u'2022-04-13', u'Quality_CheckResult': None, u'OperationId': 899L, u'ProductionOrderId': 12398955L, u'HoursSpend': 0L, u'SetterPersonalId': 0L, u'MinutesPlanned_ForOperator': None, u'isPreviousShift': 1L, u'MinutesSpend_CalculatedSinceStartOfShift': 24.55, u'Pieces_GoodCount': 0L, u'OperatorPersonalId': 1123L, u'Pieces_ScrapProcessCount': 0L, u'Note': u'', u'WorkListId': 1835485L, u'CreatedOn': 1649881413743L}

The only thing I can see wrong is u'MinutesPlanned_ForOperator': None. JSON uses null. Do you need to convert? You could do this with null = None in your code

Hi, thanks for reply but how can I access those key values ? I dont know how to read key values. The ignition says type of this object is <type 'unicode'>

If the JSON is coming is as payload then you can access each item as a Python dictionary item. e.g., payload['Shift'].

I think the problem is that your message handler isn’t recognising the payload as valid JSON. (I’m not an expert on these matters.)

I figured it out, I had to encode dictionary to json string, then it was saved as string, then was passed between components and then I decoded it again to dictionary.

At first I used it as dictionary but the parameter was set to string so ignition wrapped it in the object and therefore I could not decode it

You should not have to en/decode it to json


Whenever I run across this issue, usually casting the entire payload to a dictionary type removes the object wrapper and allows for normal scripting interactions.

Victor is right, encoding to json shouldn’t be needed. How are you passing the payload to sendMessage() ?

but the problem was I was sending it as a Value not as an object. We have one component from Projects which is inherited and the component there has input parameter Value, so whenever I send there the Dictionary it got wrapped, because Value != Object i think, or I am understanding something wrong ?

if you are passing along a dict "rowData.toDict() " than it should work.
i cant really say what your Value means or is without seeing some code.
But you really shouldnt have to decode/encode it with json