JythonMap item assignment

Hi,

I have an array of JythonMap in my TimeSeriesChart. I would like to change t_stamp item to time item.
Is it possible ?
One element below :

{
  "t_stamp": "2021-10-25 00:00:00",
  "converted": "489.406",
  "expected": "702.51",
  "basic": "42.1",
  "a0": "3.6"
}

This element after update.

{
  "time": "2021-10-25 00:00:00",
  "converted": "489.406",
  "expected": "702.51",
  "basic": "42.1",
  "a0": "3.6"
}

Mu code below doesn’t work :

for row in value:
	row['time'] = row['t_stamp']
	del row['t_stamp']

Thanks

Code works for me, at least in the Script Console, so I would expect it to work in other places, assuming that value is some type of sequence of maps.

If value is just a map, then this code doesn’t work.

Another option would be to use pop() to remove the item, something like:

for row in value:
    row['time'] = row['t_stamp']
    row.pop('t_stamp')

Again, assuming that value is a sequence of maps.

for row in value:
	row['time'] = row['t_stamp']
	row.pop('t_stamp')

image

Try changing it to Pydict with .toDict() or Java.util.map with .getRawMap()

2 Likes

You might have to convert to a dict before doing the assignment, or build a new dict from the JythonMap and use this instead:

return [
    {
        'time': item['t_stamp'],
        'converted': item['converted'],
        'expected': item['expected'],
        'basic': item['basic'],
        'a0': item['a0']
    } for item in value
]
2 Likes

It works thanks

1 Like