Properties with spaces in template node: how?

I'm looking to use a template node to build a message that is being thrown together using properties of an object that has spaces in some of the properties. In a previous version of the flow, I manually moved all of these values to camel case named properties, but I'd like to avoid that going forward as the folks supplying me with the file I start with are starting to make changes willy nilly and I'd prefer to update the flow in as few places as possible when the need arises. The property I'm after in our typical notation would be payload["First Name"], but it seems mustache format doesn't like that. I did a bit of looking and came across multiple suggestions, none of which seem to work. I know this has to be simple. Any pointers?

Try {{msg.payload[First Name]}}

I do not think that will work, the variable naming convention is the same as c++ i believe.

  1. The names can range from 1 to 255 characters. However, the recommended name size is 1 to 31 characters.
  2. All variable names should begin with either a letter of the alphabet or an underscore _.
  3. After the first letter, a variable name can contain letters or numbers.
  4. Special characters or spaces are not allowed.
  5. Variable names are case sensitive.

Also Mustache does not use square bracket notation.

@JayDickson I think you would need to convert spaces in property names to underscores. Maybe something like

for(const [key,value] of Object.entries(msg.payload)){
   if(key.includes(" ")){
       msg.payload[key.trim().replace(/\s+/g, "_")] = value;
       delete msg.payload[key];
return msg;

This would be before the template node. This code is only for payload properties and would need editing for any property of the msg.

[edit] you could switch to template strings in the function node instead.

With mustache you can do {{payload.First Name}}

Thanks for taking the time to reply. As usual you nailed it. For others who may stumble across this, I also gave it a try with that property in the location payload[0]["First Name"] (the format that the influxDB node likes to spit out a result in) and the winning solution in the template node was {{payload.0.First Name}}.

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