# Populating dashboard options

**URL:** https://discourse.nodered.org/t/populating-dashboard-options/78468
**Category:** Dashboard
**Created:** [16 May 2023 14:35 UTC](https://discourse.nodered.org/t/populating-dashboard-options/78468 "2023-05-16T14:35:46Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)
#### Post date: [16 May 2023 14:35 UTC](https://discourse.nodered.org/t/populating-dashboard-options/78468/1 "2023-05-16T14:35:46Z")

</div>

There are several posts about this subject but I can't make them work with my data.

Given this input

```auto
let locations = [
    {"Camberwell": 
        { 
        "name": "Camberwell",
        "latitude": 51.3, 
        "longitude": -0.5,
        "creation": "2023-05-16T12:34:40.068Z", 
        "lastseen": "2023-05-16T12:34:40.068Z", 
        "borough": "Southwark"
        }
    }, 
    {"Seven Dials": 
       {
        "name": "Seven Dials",
        "latitude": 51.4,
        "longitude": -0.2, 
        "creation": "2023-05-16T12:35:22.813Z", 
        "borough": "Camden" 
        }
}
]

```

I cannot convert it to pass to a dashboard dropdown as msg.options

```auto
[{"Camberwell": "Southwark"}, {"Seven Dials": "Camden"}]

```

Can someone please show me the way? Either JSONata or function code !

ps the input data could perhaps be created like this, if it makes more sense.

```auto
let locations = [
    {
            "name": "Camberwell",
            "latitude": 51.3,
            "longitude": -0.5,
            "creation": "2023-05-16T12:34:40.068Z",
            "lastseen": "2023-05-16T12:34:40.068Z",
            "borough": "Southwark"
    },
    {
            "name": "Seven Dials",
            "latitude": 51.4,
            "longitude": -0.2,
            "creation": "2023-05-16T12:35:22.813Z",
            "borough": "Camden"
    }
]

```

---

<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: [16 May 2023 14:57 UTC](https://discourse.nodered.org/t/populating-dashboard-options/78468/2 "2023-05-16T14:57:25Z")

</div>

If the array is in msg.payload then the JSONata would be

```auto
$$.payload.{$.*.name: $.*.borough}[]
//or
$$.payload.*.{$.name: $.borough}[]

```

```auto
[{"id":"9222d528a6f09111","type":"inject","z":"b9860b4b9de8c8da","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[{\"Camberwell\":{\"name\":\"Camberwell\",\"latitude\":51.3,\"longitude\":-0.5,\"creation\":\"2023-05-16T12:34:40.068Z\",\"lastseen\":\"2023-05-16T12:34:40.068Z\",\"borough\":\"Southwark\"}},{\"Seven Dials\":{\"name\":\"Seven Dials\",\"latitude\":51.4,\"longitude\":-0.2,\"creation\":\"2023-05-16T12:35:22.813Z\",\"borough\":\"Camden\"}}]","payloadType":"json","x":90,"y":2580,"wires":[["5bb02cf5ce9ef9fc"]]},{"id":"5bb02cf5ce9ef9fc","type":"change","z":"b9860b4b9de8c8da","name":"","rules":[{"t":"set","p":"options","pt":"msg","to":"$$.payload.{$.*.name: $.*.borough}[]","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":280,"y":2580,"wires":[["7731f4e21f67fee5"]]},{"id":"7731f4e21f67fee5","type":"debug","z":"b9860b4b9de8c8da","name":"debug 295","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"options","statusVal":"","statusType":"auto","x":510,"y":2580,"wires":[]}]

```

[edit] Correct blunder in flow example, set property to options in change node.

---

<div class="post-metadata">

### Author: ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)
#### Post date: [16 May 2023 19:26 UTC](https://discourse.nodered.org/t/populating-dashboard-options/78468/3 "2023-05-16T19:26:04Z")

</div>

Excellent thanks @E1cid. I had to adjust your change node to set msg.options instead of msg.payload but the dropdown works now.

---

<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: [15 June 2023 19:27 UTC](https://discourse.nodered.org/t/populating-dashboard-options/78468/4 "2023-06-15T19:27:03Z")

</div>

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