# Newbie question on changing abbreviations to string from array

**URL:** <https://discourse.nodered.org/t/newbie-question-on-changing-abbreviations-to-string-from-array/42355>\
**Category:** General\
**Created:** [9 March 2021 17:31 UTC](https://discourse.nodered.org/t/newbie-question-on-changing-abbreviations-to-string-from-array/42355 "2021-03-09T17:31:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![viixxiiv](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/viixxiiv/32/38547_2.png) [@viixxiiv](https://discourse.nodered.org/u/viixxiiv)\
**Post date:** [9 March 2021 17:31 UTC](https://discourse.nodered.org/t/newbie-question-on-changing-abbreviations-to-string-from-array/42355/1 "2021-03-09T17:31:32Z")

</div>

Hi all! I’ve just starting putting together my first node red project but and stuck.  
I managed to make an api call and extracted the data I want but it’s in an abbreviated form.

I want to convert it to a string base on this array? But have no idea how to do it (no programming background)

I’ve looked through all the examples and tutorials and I’m guessing I’ve to use a function node but am getting nowhere.

How do I get an incoming msg payload eg. FG to convert it to the corresponding FOG base on the below?

{  
'BR': 'Mist',  
'CL': 'Cloudy',  
'DR': 'Drizzle',  
'FA': 'Fair',  
'FG': 'Fog',  
'FN': 'Fair (Night)',  
'FW': 'Fair & Warm',  
'HG': 'Heavy Thundery Showers with Gusty Winds',  
'HR': 'Heavy Rain',  
'HS': 'Heavy Showers',  
'HT': 'Heavy Thundery Showers',  
'HZ': 'Hazy',  
'LH': 'Slightly Hazy',  
'LR': 'Light Rain',  
'LS': 'Light Showers',  
'OC': 'Overcast',  
'PC': 'Partly Cloudy',  
'PN': 'Partly Cloudy (Night)',  
'PS': 'Passing Showers',  
'RA': 'Moderate Rain',  
'SH': 'Showers',  
'SK': 'Strong Winds, Showers',  
'SN': 'Snow',  
'SR': 'Strong Winds, Rain',  
'SS': 'Snow Showers',  
'SU': 'Sunny',  
'SW': 'Strong Winds',  
'TL': 'Thundery Showers',  
'WC': 'Windy, Cloudy',  
'WD': 'Windy',  
'WF': 'Windy, Fair',  
'WR': 'Windy, Rain',  
'WS': 'Windy, Showers',  
}

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [9 March 2021 17:41 UTC](https://discourse.nodered.org/t/newbie-question-on-changing-abbreviations-to-string-from-array/42355/2 "2021-03-09T17:41:11Z")

</div>

> [@viixxiiv](#):
>
> I want to convert it to a string base on this array?

What you have is JSON and if you use a JSON node you will end up with a JS object. From that you can use any or all parts of it to generate whatever string you like.

As you are new to node-red, I strongly recommend watching this playlist: [Node-RED Essentials](https://www.youtube.com/playlist?list=PLyNBB9VCLmo1hyO-4fIZ08gqFcXBkHy-6). The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour. A small investment for a lot of gain.

Edit...

I may have spoken too soon. That is not valid JSON

Where did that come from? Surely not an API? Show us a screenshot of the debug message and your flow.

---

<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:** [9 March 2021 17:56 UTC](https://discourse.nodered.org/t/newbie-question-on-changing-abbreviations-to-string-from-array/42355/3 "2021-03-09T17:56:27Z")

</div>

You would use the object you showed , and use it to look up the string.

```auto
[{"id":"b69e6a45.2550a8","type":"inject","z":"5a245aa1.510164","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"HT","payloadType":"str","x":140,"y":2820,"wires":[["80a744b0.ec3e78"]]},{"id":"80a744b0.ec3e78","type":"function","z":"5a245aa1.510164","name":"","func":"// create lookup table this could also be store in context\nvar lookup = { \n'BR': 'Mist',\n'CL': 'Cloudy',\n'DR': 'Drizzle',\n'FA': 'Fair',\n'FG': 'Fog',\n'FN': 'Fair (Night)',\n'FW': 'Fair & Warm',\n'HG': 'Heavy Thundery Showers with Gusty Winds',\n'HR': 'Heavy Rain',\n'HS': 'Heavy Showers',\n'HT': 'Heavy Thundery Showers',\n'HZ': 'Hazy',\n'LH': 'Slightly Hazy',\n'LR': 'Light Rain',\n'LS': 'Light Showers',\n'OC': 'Overcast',\n'PC': 'Partly Cloudy',\n'PN': 'Partly Cloudy (Night)',\n'PS': 'Passing Showers',\n'RA': 'Moderate Rain',\n'SH': 'Showers',\n'SK': 'Strong Winds, Showers',\n'SN': 'Snow',\n'SR': 'Strong Winds, Rain',\n'SS': 'Snow Showers',\n'SU': 'Sunny',\n'SW': 'Strong Winds',\n'TL': 'Thundery Showers',\n'WC': 'Windy, Cloudy',\n'WD': 'Windy',\n'WF': 'Windy, Fair',\n'WR': 'Windy, Rain'\n}\nmsg.payload=lookup[msg.payload];\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":290,"y":2820,"wires":[["f1b82c93.f6263"]]},{"id":"f1b82c93.f6263","type":"debug","z":"5a245aa1.510164","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":510,"y":2820,"wires":[]}]

```

The lookup object could also be stored in context storage rather than in the function. This could also be done in a change node with JSONata expression, and as of node-red 1.3 you could also do it with out JOSNata.

---

<div class="post-metadata">

**Author:** ![shrickus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shrickus/32/517_2.png) [@shrickus](https://discourse.nodered.org/u/shrickus)\
**Post date:** [10 March 2021 17:09 UTC](https://discourse.nodered.org/t/newbie-question-on-changing-abbreviations-to-string-from-array/42355/4 "2021-03-10T17:09:28Z")

</div>

> [@Steve-Mcl](#):
>
> That is not valid JSON

Steve is correct -- but a simple string substitution to change single quotes to double quotes would make it valid, it seems. Then the modified string could be passed to the `json` node to turn it into a proper lookup table.

---

<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:** [9 May 2021 17:09 UTC](https://discourse.nodered.org/t/newbie-question-on-changing-abbreviations-to-string-from-array/42355/5 "2021-05-09T17:09:32Z")

</div>

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