# Complex Context Variables

**URL:** <https://discourse.nodered.org/t/complex-context-variables/28631>\
**Category:** General\
**Created:** [19 June 2020 18:56 UTC](https://discourse.nodered.org/t/complex-context-variables/28631 "2020-06-19T18:56:40Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dparm](https://avatars.discourse-cdn.com/v4/letter/d/47e85d/32.png) [@dparm](https://discourse.nodered.org/u/dparm)\
**Post date:** [19 June 2020 18:56 UTC](https://discourse.nodered.org/t/complex-context-variables/28631/1 "2020-06-19T18:56:40Z")

</div>

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:

```auto
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:

```auto
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! 😀 👍

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [19 June 2020 19:10 UTC](https://discourse.nodered.org/t/complex-context-variables/28631/2 "2020-06-19T19:10:35Z")

</div>

You should be able to do it with:

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

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [19 June 2020 19:35 UTC](https://discourse.nodered.org/t/complex-context-variables/28631/3 "2020-06-19T19:35:30Z")

</div>

> [@dparm](#):
>
> ```auto
> Data: {
> {
> 
> ```

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

---

<div class="post-metadata">

**Author:** ![dparm](https://avatars.discourse-cdn.com/v4/letter/d/47e85d/32.png) [@dparm](https://discourse.nodered.org/u/dparm)\
**Post date:** [19 June 2020 23:14 UTC](https://discourse.nodered.org/t/complex-context-variables/28631/4 "2020-06-19T23:14:32Z")

</div>

This one worked. Thanks! 🙏

---

<div class="post-metadata">

**Author:** ![dparm](https://avatars.discourse-cdn.com/v4/letter/d/47e85d/32.png) [@dparm](https://discourse.nodered.org/u/dparm)\
**Post date:** [19 June 2020 23:15 UTC](https://discourse.nodered.org/t/complex-context-variables/28631/5 "2020-06-19T23:15:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [3 July 2020 23:15 UTC](https://discourse.nodered.org/t/complex-context-variables/28631/6 "2020-07-03T23:15:25Z")

</div>

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