MQTT array, display only 1 value

Hi there,

Using MQTT Engine, im receiving an array of string, which I want to display only one of the string from the array. Im trying to index the array by using "[2]", but it displays all the strings in the array anyway. How can i display only ie. number 2?

The MQTT variable:

Indexing and displaying the array, still gives all values.

Any ideas? :slight_smile:

Have you tried using a script transform on the value? Perhaps something like list(value)[1] would work.

It's probably nothing to do with the problem but you've shown the Hops names variable content but your binding is for Hops use.

I've created a string array memory tag and can access each element as you are without difficulty. Can you show us the contents of Hops use?

Hi, your right i missed that. But the problem is the same for both, and also more variables.

Well, i'm no good with the scripting part... How should I do this? :slight_smile:

You've created a Script Transform. Justin's given you an Expression Transform.

Remove the [1] from your tag path.
Delete the script transform.
Create an expression transform.
Paste his code straight in and that's it.

Think of expressions as being like Excel functions. It's not a program script but rather one or more functions or operations on variables and it just returns one result (or result set).

Thank you :slight_smile:

I get this error :confused:

Hover over the Error_Configuration error to read what the problem is.


Sorry, I'm having a bad day. list() is a script function, not an expression function. Your first attempt was right but Justin, I think, missed the { } braces. Try modifying the script to,

{value} is what's passed into the transform from the previous operation.

Uhm, different error this time as you see, list function is unknows :confused:

As script:

I modified my previous post. It may be better to wait on someone else to respond!

Question for anyone else reading the thread:

Vidar's MQTT tags display in Tag Browser are displayed as an array / list like this:

When I created a string array for testing it shows up like this:
String array

Can you explain why?

Thats strange... Any chance that this has something to do with MQTT to do? Im publishing data from Nodered/MQTT. The data from nodered looks like this (array):


Then, it is sent via MQTT node. Not sure what is done with the data inside this node. Maybe its sent as 1 complete string, instead of array?

Or maybe not, when i subscribe to this topic it is displayed as array:

I would expect this expression transform to work:


Check the data type on the actual tag you're getting. I suspect it's passing it as a JSON string and not an array.

Edit: If this is the case, you'll need something like:


Thanks, not sure where to check which data type is recieved...

No luck with the jsonGet either... :confused:

Actually, this worked! :slight_smile:

1 Like

Glad it worked for you.
I just realized I should have left off the return (I was mixing up expressions with scripting there for a bit). I'll edit it so no one else gets confused by it either.

Usually there's a 3rd column that shows what your datatype is that I'm not seeing in your screenshot.

Ah! Data type column wasn't active, but it says its a string

1 Like