Complex Context Variables

I've been having issues setting and getting data from a context variable named "Data". The variable in question is a JSON object that looks similar to this:

Data: {
        "I.Data[0]": -51,
        "I.Data[1]": -52,
        "I.Data[2]": -52,
        "I.Data[3]": 60

I keep trying to set individual key values inside of the variable with no luck. I think my problem is there must be a particular way to do this that is unlike accessing other JSON objects. I've tried things such as:

flow.set('Data'['I.Data[0]'], value);

flow.set('Data'.'I.Data[0]]', value);

flow.Data.set("I.Data[0]", value);

flow.set(Data."I.Data[0]", value);

All of these just error'ed out. The only thing that seems to work is creating a dummy JSON object, committing the new values to the dummy object, and then setting the entire variable to the dummy object. This of course is not only inelegant but could also problems down the road if the number of keys is large.

Any help would be greatly appreciated.

Thanks! :grinning: :+1:

You should be able to do it with:

flow.set('Date["I.Data[0]"]', value);
1 Like

That isn't a valid structure is it? With double braces round the object.

1 Like

This one worked. Thanks! :pray:

I must have typed it in wrong. I was pulling directly from a msg.payload, so it was formatted correctly when in use.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.