# How to access data from a JSON file using a specific key

**URL:** <https://discourse.nodered.org/t/how-to-access-data-from-a-json-file-using-a-specific-key/78216>\
**Category:** General\
**Tags:** function-node\
**Created:** [6 May 2023 01:56 UTC](https://discourse.nodered.org/t/how-to-access-data-from-a-json-file-using-a-specific-key/78216 "2023-05-06T01:56:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![thanawit888](https://avatars.discourse-cdn.com/v4/letter/t/aeb1de/32.png) [@thanawit888](https://discourse.nodered.org/u/thanawit888)\
**Post date:** [6 May 2023 01:56 UTC](https://discourse.nodered.org/t/how-to-access-data-from-a-json-file-using-a-specific-key/78216/1 "2023-05-06T01:56:33Z")

</div>

form{  
"id": "0002",  
"data": {  
"data\_type": "cmd\_v3",  
"id": "0002",  
"n": "fcu\_01",  
"function": "write",  
"item": [  
{  
"n": "power",  
"data": "v"  
},  
{  
"n": "set\_temp",  
"data": v  
},  
{  
"n": "fan\_speed",  
"data": "v"  
},  
{  
"n": "mode",  
"data": "v"  
}  
]  
}  
}

i wat to access data like  
n: set\_temp data = "v"  
n : fan\_speed data = "v"  
n: mode data = "v"  
n : power data = "v"  
how can i make this without calling through the array position. Thank

---

<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:** [6 May 2023 07:40 UTC](https://discourse.nodered.org/t/how-to-access-data-from-a-json-file-using-a-specific-key/78216/2 "2023-05-06T07:40:43Z")

</div>

You could reform the data to an object  
then call the data `msg.payload.set_temp`  
e.g.

```auto
[{"id":"474599d714e96bb9","type":"inject","z":"1d319bc3005a51a2","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"form\":{\"id\":\"0002\",\"data\":{\"data_type\":\"cmd_v3\",\"id\":\"0002\",\"n\":\"fcu_01\",\"function\":\"write\",\"item\":[{\"n\":\"power\",\"data\":\"v\"},{\"n\":\"set_temp\",\"data\":\"v\"},{\"n\":\"fan_speed\",\"data\":\"v\"},{\"n\":\"mode\",\"data\":\"v\"}]}}}","payloadType":"json","x":130,"y":280,"wires":[["4aaf250378451bf5"]]},{"id":"4aaf250378451bf5","type":"change","z":"1d319bc3005a51a2","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$$.payload.form.data.item.${$.n:$.data}","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":300,"y":280,"wires":[["3b64295684b6c8c2"]]},{"id":"3b64295684b6c8c2","type":"debug","z":"1d319bc3005a51a2","name":"debug 4 flow 3","active":true,"tosidebar":true,"console":true,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":530,"y":280,"wires":[]}]

```

Output

```auto
{ 
  "power":"v",
  "set_temp":"v",
  "fan_speed":"v",
  "mode":"v"
}

```

---

<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:** [20 May 2023 07:41 UTC](https://discourse.nodered.org/t/how-to-access-data-from-a-json-file-using-a-specific-key/78216/3 "2023-05-20T07:41:04Z")

</div>

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