# Extract object name and put it in a flow variable (help needed)

**URL:** <https://discourse.nodered.org/t/extract-object-name-and-put-it-in-a-flow-variable-help-needed/4676>\
**Category:** General\
**Created:** [8 November 2018 10:03 UTC](https://discourse.nodered.org/t/extract-object-name-and-put-it-in-a-flow-variable-help-needed/4676 "2018-11-08T10:03:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![iridiu](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/iridiu/32/1213_2.png) [@iridiu](https://discourse.nodered.org/u/iridiu)\
**Post date:** [8 November 2018 10:03 UTC](https://discourse.nodered.org/t/extract-object-name-and-put-it-in-a-flow-variable-help-needed/4676/1 "2018-11-08T10:03:41Z")

</div>

I am trying to setup a router from Node-Red dashboard via JSON-RPC, payload response received from router is a JSON object:  
`{"_msgid":"124cf3d6.b47a9c","topic":"","payload":{"jsonrpc":"2.0","id":6,"result":[0,{"values":{"cfg023579":{".anonymous":true,".type":"wifi-iface",".name":"cfg023579",".index":1,"device":"radio0","network":"lan","mode":"ap","isolate":"0","user_enable":"1","hotspotid":"hotspot1","ssid":"HOOS","key":"development","ttl_increase":"0","encryption":"psk-mixed"}}}]},"statusCode":200,"responseUrl":"http://192.168.200.2/ubus","headers":{"connection":"close","transfer-encoding":"chunked","x-frame-options":"SAMEORIGIN","content-type":"application/json","x-node-red-request-node":"3156b968"}}`

From this payload I want to extract the name of the object "cfg023579" which is dynamic and put it in a flow variable:

 ![Object%20name](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/0/0f4aaf23554005378499d4779411f8e07250962d.jpeg)

After this, to acces the values I need to use the flow variable:

 ![Object%20name%20variable](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/2/2bdca9bfa66b6479fa05313e00efcfe1b1baf84f.jpeg)

---

<div class="post-metadata">

**Author:** ![iridiu](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/iridiu/32/1213_2.png) [@iridiu](https://discourse.nodered.org/u/iridiu)\
**Post date:** [8 November 2018 13:07 UTC](https://discourse.nodered.org/t/extract-object-name-and-put-it-in-a-flow-variable-help-needed/4676/2 "2018-11-08T13:07:57Z")

</div>

I found a way to extract the object name and put it in a flow variable, but how I include the value of the variable in the payload path?

msgSSID.payload = msg.payload.result[1].values.cfg023579.ssid;

cfg023579 to be variable value...

---

<div class="post-metadata">

**Author:** ![Andrei](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andrei/32/10446_2.png) [@Andrei](https://discourse.nodered.org/u/Andrei)\
**Post date:** [8 November 2018 13:16 UTC](https://discourse.nodered.org/t/extract-object-name-and-put-it-in-a-flow-variable-help-needed/4676/3 "2018-11-08T13:16:59Z")

</div>

jsonata is a good solution for this use case.

For instance, the expression: `$keys($.payload.result.values)` applied to your payload will result in an array of keys

```auto
[
  "cfg023579"
]

```

Probably you will need to modify a little below flow to suit your payload:

```auto
[{"id":"b341cefe.91247","type":"tab","label":"Flow 3","disabled":false,"info":""},{"id":"9eb950ef.2adea","type":"inject","z":"b341cefe.91247","name":"Trigger","topic":"","payload":"{\"_msgid\":\"124cf3d6.b47a9c\",\"topic\":\"\",\"payload\":{\"jsonrpc\":\"2.0\",\"id\":6,\"result\":[0,{\"values\":{\"cfg023579\":{\".anonymous\":true,\".type\":\"wifi-iface\",\".name\":\"cfg023579\",\".index\":1,\"device\":\"radio0\",\"network\":\"lan\",\"mode\":\"ap\",\"isolate\":\"0\",\"user_enable\":\"1\",\"hotspotid\":\"hotspot1\",\"ssid\":\"HOOS\",\"key\":\"development\",\"ttl_increase\":\"0\",\"encryption\":\"psk-mixed\"}}}]},\"statusCode\":200,\"responseUrl\":\"http://192.168.200.2/ubus\",\"headers\":{\"connection\":\"close\",\"transfer-encoding\":\"chunked\",\"x-frame-options\":\"SAMEORIGIN\",\"content-type\":\"application/json\",\"x-node-red-request-node\":\"3156b968\"}}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":250,"y":300,"wires":[["e1127e10.612fb","4339c31.5b0e93c"]]},{"id":"c119f43.dd8c308","type":"debug","z":"b341cefe.91247","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":610,"y":300,"wires":[]},{"id":"e1127e10.612fb","type":"change","z":"b341cefe.91247","name":"","rules":[{"t":"set","p":"result","pt":"msg","to":"$keys($.payload.payload.result.values)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":440,"y":300,"wires":[["c119f43.dd8c308"]]},{"id":"4339c31.5b0e93c","type":"debug","z":"b341cefe.91247","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":430,"y":240,"wires":[]}]

```

Now, if the ultimate goal is to extract the SSID from the object then the jsonata expression would be as simple as `**.ssid`, resulting in `"HOOS"`

Flow:

```auto
[{"id":"b341cefe.91247","type":"tab","label":"Flow 3","disabled":false,"info":""},{"id":"9eb950ef.2adea","type":"inject","z":"b341cefe.91247","name":"Trigger","topic":"","payload":"{\"_msgid\":\"124cf3d6.b47a9c\",\"topic\":\"\",\"payload\":{\"jsonrpc\":\"2.0\",\"id\":6,\"result\":[0,{\"values\":{\"cfg023579\":{\".anonymous\":true,\".type\":\"wifi-iface\",\".name\":\"cfg023579\",\".index\":1,\"device\":\"radio0\",\"network\":\"lan\",\"mode\":\"ap\",\"isolate\":\"0\",\"user_enable\":\"1\",\"hotspotid\":\"hotspot1\",\"ssid\":\"HOOS\",\"key\":\"development\",\"ttl_increase\":\"0\",\"encryption\":\"psk-mixed\"}}}]},\"statusCode\":200,\"responseUrl\":\"http://192.168.200.2/ubus\",\"headers\":{\"connection\":\"close\",\"transfer-encoding\":\"chunked\",\"x-frame-options\":\"SAMEORIGIN\",\"content-type\":\"application/json\",\"x-node-red-request-node\":\"3156b968\"}}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":250,"y":300,"wires":[["e1127e10.612fb"]]},{"id":"c119f43.dd8c308","type":"debug","z":"b341cefe.91247","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":610,"y":300,"wires":[]},{"id":"e1127e10.612fb","type":"change","z":"b341cefe.91247","name":"","rules":[{"t":"set","p":"result","pt":"msg","to":"**.ssid","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":440,"y":300,"wires":[["c119f43.dd8c308"]]}]

```

![r-01](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/a/aa5d6d2af6be722cd0c564706d35a2fc2ffe9965.png)

---

<div class="post-metadata">

**Author:** ![iridiu](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/iridiu/32/1213_2.png) [@iridiu](https://discourse.nodered.org/u/iridiu)\
**Post date:** [8 November 2018 13:36 UTC](https://discourse.nodered.org/t/extract-object-name-and-put-it-in-a-flow-variable-help-needed/4676/4 "2018-11-08T13:36:44Z")

</div>

> [@Andrei](#):
>
> ```auto
> [{"id":"b341cefe.91247","type":"tab","label":"Flow 3","disabled":false,"info":""},{"id":"9eb950ef.2adea","type":"inject","z":"b341cefe.91247","name":"Trigger","topic":"","payload":"{\"_msgid\":\"124cf3d6.b47a9c\",\"topic\":\"\",\"payload\":{\"jsonrpc\":\"2.0\",\"id\":6,\"result\":[0,{\"values\":{\"cfg023579\":{\".anonymous\":true,\".type\":\"wifi-iface\",\".name\":\"cfg023579\",\".index\":1,\"device\":\"radio0\",\"network\":\"lan\",\"mode\":\"ap\",\"isolate\":\"0\",\"user_enable\":\"1\",\"hotspotid\":\"hotspot1\",\"ssid\":\"HOOS\",\"key\":\"development\",\"ttl_increase\":\"0\",\"encryption\":\"psk-mixed\"}}}]},\"statusCode\":200,\"responseUrl\":\"http://192.168.200.2/ubus\",\"headers\":{\"connection\":\"close\",\"transfer-encoding\":\"chunked\",\"x-frame-options\":\"SAMEORIGIN\",\"content-type\":\"application/json\",\"x-node-red-request-node\":\"3156b968\"}}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":250,"y":300,"wires":[["e1127e10.612fb"]]},{"id":"c119f43.dd8c308","type":"debug","z":"b341cefe.91247","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":610,"y":300,"wires":[]},{"id":"e1127e10.612fb","type":"change","z":"b341cefe.91247","name":"","rules":[{"t":"set","p":"result","pt":"msg","to":"**.ssid","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":440,"y":300,"wires":[["c119f43.dd8c308"]]}]
> 
> ```

Thank you very much @Andrei, it's working!

![Object%20name](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/b/b15c6c93e8fb75fd4560f28e84aa21c46dc75aee.jpeg)
