# ui-Control JSON Format

**URL:** <https://discourse.nodered.org/t/ui-control-json-format/81729>\
**Category:** Dashboard\
**Created:** [2 October 2023 17:53 UTC](https://discourse.nodered.org/t/ui-control-json-format/81729 "2023-10-02T17:53:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![n61ab](https://avatars.discourse-cdn.com/v4/letter/n/cc9497/32.png) [@n61ab](https://discourse.nodered.org/u/n61ab)\
**Post date:** [2 October 2023 17:53 UTC](https://discourse.nodered.org/t/ui-control-json-format/81729/1 "2023-10-02T17:53:35Z")

</div>

Here is the JSON msg.payload I am using as an input to the ui-Control Node:

```auto
{"group":{"hide":["Memory_Memory-Name","Memory_New","Memory_Memory","Memory_Backup","Memory_Update"],"show":["Memory_Memory-Select"]}}

```

The target tab is "Memory". Work good.

But, I want to re-write the object to target tab zero (0), so that if the name of the tab changes, the ui\_Control will continue to work.

I have tried different JSON objects, but none work.

I need help. Re-Write the above ui\_Control msg.payload to use tab (0), instead of tab "Memory".

Alan

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [2 October 2023 20:44 UTC](https://discourse.nodered.org/t/ui-control-json-format/81729/2 "2023-10-02T20:44:39Z")

</div>

First not possible directly using msg.tab, ie `0`

You would first need to load your flow json, then filter out all ui\_tab types and return the name properties.  
Then you can us index 0 to add the property name to the group json.  
e.g

```auto
[{"id":"0965bb151a929dda","type":"inject","z":"d1395164b4eec73e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":380,"y":560,"wires":[["8fb335c0a1db20b7"]]},{"id":"8fb335c0a1db20b7","type":"file in","z":"d1395164b4eec73e","name":"","filename":"/your/path/to/flows.json","filenameType":"str","format":"utf8","chunk":false,"sendError":false,"encoding":"none","allProps":false,"x":590,"y":560,"wires":[["d478de8751a8671a"]]},{"id":"d478de8751a8671a","type":"json","z":"d1395164b4eec73e","name":"","property":"payload","action":"","pretty":false,"x":650,"y":620,"wires":[["9db607cc713c5d35"]]},{"id":"9db607cc713c5d35","type":"change","z":"d1395164b4eec73e","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"(\t $tabs := $$.payload[$.type = \"ui_tab\"].name;\t {\t \"group\":{\t \"hide\":[\t $tabs[0] & \"_Memory-Name\",\t $tabs[0] & \"_New\",\t $tabs[0] & \"_Memory\",\t $tabs[0] & \"_Backup\",\t $tabs[0] & \"_Update\"\t ],\t \"show\":[\t $tabs[0] & \"_Memory-Select\"\t ]\t }\t }\t)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":820,"y":620,"wires":[["13ac52b76848d01c"]]},{"id":"13ac52b76848d01c","type":"debug","z":"d1395164b4eec73e","name":"debug 344","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":990,"y":620,"wires":[]}]

```

`Home` is my tab 0

 ![chrome_screenshot_1696279318569](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/f/4fbdc455c884ddc5f3b596783bae7fc14dbec4a4.png)  
JSONata expression to create payload object

```auto
(
    $tabs := $$.payload[$.type = "ui_tab"].name;
    {
        "group":{
            "hide":[
                $tabs[0] & "_Memory-Name",
                $tabs[0] & "_New",
                $tabs[0] & "_Memory",
                $tabs[0] & "_Backup",
                $tabs[0] & "_Update"
            ],
            "show":[
                $tabs[0] & "_Memory-Select"
            ]
        }
    }
)

```

You could probably save the tabs array to a context var on a daily basis and then just reference that if you wanted to, or watch the flow.json file for changes, then update the tabs array if the file has changed.

---

<div class="post-metadata">

**Author:** ![n61ab](https://avatars.discourse-cdn.com/v4/letter/n/cc9497/32.png) [@n61ab](https://discourse.nodered.org/u/n61ab)\
**Post date:** [2 October 2023 21:12 UTC](https://discourse.nodered.org/t/ui-control-json-format/81729/3 "2023-10-02T21:12:05Z")

</div>

E1CD. Thanks.

I did something similar, but I thought there should be an easier way.

I used the ui-Control node to get the tab 0 (msg.tab) and name (msg.name), and put tab 0's, name into flow context as "tab".

Then I used a function node to build the ui-Control JSON concating the string: tab + "\_group-name"

Since you say there is no way to write the JSON directly, I will mark this question as solved.

Alan

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [2 October 2023 21:24 UTC](https://discourse.nodered.org/t/ui-control-json-format/81729/4 "2023-10-02T21:24:22Z")

</div>

> [@n61ab](#):
>
> I did something similar, but I thought there should be an easier way.
> 
> I used the ui-Control node to get the tab 0 (msg.tab) and name (msg.name), and put tab 0's, name into flow context as "tab".
> 
> Then I used a function node to build the ui-Control JSON concating the string: tab + "\_group-name"
> 
> Since you say there is no way to write the JSON directly, I will mark this question as solved.

Next time could you provide all the relevant info, so people don't waste time providing solutions that you have already tried.

If you have a solution please provide it for others to use, marking a post the solution should really contain a solution, with a clear example.

---

<div class="post-metadata">

**Author:** ![n61ab](https://avatars.discourse-cdn.com/v4/letter/n/cc9497/32.png) [@n61ab](https://discourse.nodered.org/u/n61ab)\
**Post date:** [3 October 2023 13:37 UTC](https://discourse.nodered.org/t/ui-control-json-format/81729/5 "2023-10-03T13:37:41Z")

</div>

E1CD

Your point is well taken. I do appreciate the effort you put into my original question.

Alan

---

<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:** [17 October 2023 13:37 UTC](https://discourse.nodered.org/t/ui-control-json-format/81729/6 "2023-10-17T13:37:54Z")

</div>

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